Indexes live in RAM but are written to disk frequently so you don’t have to rebuild them if you restart your mongod. For a healthy and happy mongod, all the indexes must fit in RAM.
You also need RAM for your frequently accessed documents (so you don’t have to fetch them from the disk each time - this is what we refer to as the “Working Set”)
And finally you need some RAM for your queries and pipelines and eventually in-memory sort operations (not great).
See https://docs.mongodb.com/manual/tutorial/ensure-indexes-fit-ram/.