Skip to content

Semantic Cache is not working #651

@awais-nayyar

Description

@awais-nayyar

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"similar_cache_{hashed_llm}")

set_llm_cache(GPTCache(init_gptcache))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions