Replies: 1 comment 1 reply
-
Hi @servaram! I'm Dosu and I’m helping the langchain team. To store only the user input and generated SQL in RedisSemanticCache, you should avoid custom cache key logic (like using hashlib or custom prefixes/names) and let RedisSemanticCache handle semantic matching automatically. It uses embeddings and a distance_threshold to match similar queries, so just pass the user question as the prompt—no need to cache intermediate steps or table structures. If you’re seeing empty results, double-check that your chain returns the SQL string as the main output and that you’re not caching intermediate or irrelevant data by accident. To improve semantic matching, make sure you’re not overriding the cache key logic. Remove any custom prefix or name parameters—these interfere with semantic matching. RedisSemanticCache will then embed each prompt and retrieve cached results for semantically similar queries above your distance_threshold. You can tune this threshold for stricter or looser matching. See this discussion for more details. If you want alternatives, you might consider other vector-based caches like those built on top of Milvus, Qdrant, or Chroma, but RedisSemanticCache is the most integrated with LangChain’s SQL toolkit. Also, note that SQLDatabaseChain is deprecated; consider using VectorSQLDatabaseChain for newer projects, as it’s designed for semantic retrieval and caching in SQL workflows source. For your sample code, just ensure you’re setting the cache on the LLM and not passing extra cache key logic. The cache will store and retrieve based on the user question and the generated SQL, using semantic similarity. If you want to cache only the SQL, make sure your chain’s output is just the SQL string. If you need more control, you may need to customize the chain’s return values. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was trying to use redis semantic cache for my text to sql application, based on some examples from redis and langchain, i've impletemented this. i did not find enough documention on this topic
i do see that my complete chain including intermediate queiers, table structure etc and all that's being pushed to the redis store but on the subsequent runs its just returning an empty string with no sql (only when cache is enabled and cached data available)
Beta Was this translation helpful? Give feedback.
All reactions