CachedSearch#

class scikitplot.corpus.CachedSearch(index, *, max_entries=1024)[source]#

Exact, bounded cache in front of one retrieval index.

Parameters:
indexRetrievalIndex

The index to answer from.

max_entriesint, default=1024

Responses kept; the least recently used is evicted first.

Raises:
ValueError

If max_entries is not an int of at least 1.

Parameters:
  • index (Any)

  • max_entries (int)

clear()[source]#

Drop every stored response.

Return type:

None

key(query, config=None, query_embedding=None, filter=None)[source]#

Return the cache key of a search, or None when it cannot be cached.

Returns:
str or None

64 hex digits; None for an index that is not built, or a config with probability_fusion.

Parameters:
  • query (str)

  • config (Any)

  • query_embedding (Any)

  • filter (Any)

Return type:

str | None

search(query, *, config=None, query_embedding=None, filter=None)[source]#

Answer like RetrievalIndex.search, from the cache when possible.

Returns:
RetrievalResponse

Equal to what the index returns for the same arguments.

Parameters:
  • query (str)

  • config (Any)

  • query_embedding (Any)

  • filter (Any)

Return type:

Any

stats()[source]#

Count hits, misses, stored, uncacheable and evicted, and the size.

Return type:

dict[str, int]