Skip to content

RetrievalCache

new RetrievalCache(config?): RetrievalCache;
Parameter Type

config?

RetrievalCacheConfig

RetrievalCache

get size(): number;

Total number of cached items (query entries + doc entries).

number

clear(): void;

Remove all entries from the cache.

void


lookup(queryEmbedding, topK?): RetrievalResult[];

Look up cached results by query embedding similarity.

First checks the query index (query-to-query similarity, high accuracy with asymmetric models). Falls back to the document index if no query-level match is found.

Parameter Type Default value Description

queryEmbedding

readonly number[]

undefined

The query’s embedding vector.

topK

number

5

Maximum number of results to return. Default: 5.

RetrievalResult[]

Matching cached results, or empty array on cache miss.


populate(results, queryEmbedding?): void;

Populate the cache with retrieval results and the query embedding that produced them.

When queryEmbedding is provided, stores a query-indexed entry (preferred for lookup — query-to-query similarity is high).

Also stores individual document embeddings in the document index for results that have them.

Parameter Type

results

RetrievalResult[]

queryEmbedding?

readonly number[]

void