zilliztech / GPTCache

Semantic cache for LLMs. Fully integrated with LangChain and llama_index.
https://gptcache.readthedocs.io
MIT License
7.25k stars 507 forks source link

Semantic Cache is not working #651

Open awais-nayyar opened 2 months ago

awais-nayyar commented 2 months ago

I am utilizing the GPT Semantic Cache as outlined in the Langchain documentation, combined with the Groq API and the Llama3-70b-8192 model. However, I'm encountering an issue where the semantic cache returns the same response repeatedly, even when different questions are asked. Can anybody know what could be the possible cause? Here is the code:

import hashlib

from gptcache import Cache from gptcache.adapter.api import init_similar_cache from langchain.cache import GPTCache from langchain_core.globals import set_llm_cache

def get_hashed_name(name): return hashlib.sha256(name.encode()).hexdigest()

def init_gptcache(cache_obj: Cache, llm: str): hashed_llm = get_hashed_name(llm) init_similar_cache(cache_obj=cache_obj, data_dir=f"similarcache{hashed_llm}")

set_llm_cache(GPTCache(init_gptcache))

dipanjannC commented 2 months ago

Wanted to know which vector store you're using . Are you having any issues using cloud vector stores?

awais-nayyar commented 2 months ago

according to langchain documentation of Semantic GPTCache I did not see any vector store utilization? can you please guide me or share any link from where i can get it correctly? here is the link of langchain doc of Semantic GPTCache: https://python.langchain.com/docs/integrations/llm_caching/#gptcache