Semantic Cache supports various retrieval scenarios including synonyms, multilingual queries, and complex phrasing.
Note: When running manual tests, a delay (e.g., 1 second) is often necessary after a .set() call to allow the vector index to update before performing a .get().
// Handling Synonyms
await semanticCache.set("largest city in USA by population", "New York");
await delay(1000);
const result = await semanticCache.get("which is the most populated city in the USA?"); // outputs "New York"
// Multilingual Queries (requires multilingual embedding model)
await semanticCache.set("German Chancellor", "Olaf Scholz");
await delay(1000);
const resultLang = await semanticCache.get("Wer ist der Bundeskanzler von Deutschland?"); // outputs "Olaf Scholz"
// Complex Queries
await semanticCache.set("year in which the Berlin wall fell", "1989");
await delay(1000);
const resultComplex = await semanticCache.get("what's the year the Berlin wall destroyed?"); // outputs "1989"