Trying to implement prompt caching using MongoDBCache in my RAG based document answering system but facing an issue

Hey guys!
I am working on a multimodal rag for complex pdfs (using a pdf rag chain) but i am facing an issue. I am trying to implement prompt caching using Langchain’s MongoDBCache in my RAG based document answering system.

The problem i am facing is that the query that i ask is getting stored into the MongoDBCache but, when i ask that same query again, MongoDBcache is not being used to return the response.

For example look at the screenshots: i said “hello”. that query and response got stored into the cache in second screenshot, but when i send “hello” one more time, i get a unique response, different from the previous one. ideally it should be same as previous one as the previous query and its response was cached. But that doesn’t happen, instead the second “hello” query also gets cached with a unique ID.


Note: MongoDBCache is different from Semantic Cache
code snippet:


Hi @Shikhar_Ashish, firstly, welcome to the MongoDB community forum! can you share the code snippet where you are using the LangChain MongoDBCache? In the attached code are you trying to implement your own cache?