CacheKeyGenerator

org.llm4s.llmconnect.caching.CacheKeyGenerator
@Stable

Utility object for generating cache keys using secure hashing. Keys are deterministic (the same inputs always produce the same key) and unambiguous: every part is prefixed with its length before hashing, so two different sequences of parts never hash the same input, whatever characters the parts contain.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def embeddingKey(text: String, model: String, purpose: InputPurpose): String

The default embedding cache key: the text, the model name and the purpose of the request, each encoded as a part of its own, so a query and a document with the same text never share a key, and no model name or text can stand in for another.

The default embedding cache key: the text, the model name and the purpose of the request, each encoded as a part of its own, so a query and a document with the same text never share a key, and no model name or text can stand in for another.

Value parameters

model

The model name

purpose

Whether the text is embedded as a document or as a query

text

The input text to embed

Attributes

Returns

A 64-character hex string representing the hash

def sha256(parts: String*): String

The SHA-256 of the given parts, each prefixed with its length and a colon (5:hello), so the encoding is unambiguous: sha256("a:b", "c") and sha256("a", "b:c") are different keys. Use it to build a key function of your own that adds parts, such as a tenant.

The SHA-256 of the given parts, each prefixed with its length and a colon (5:hello), so the encoding is unambiguous: sha256("a:b", "c") and sha256("a", "b:c") are different keys. Use it to build a key function of your own that adds parts, such as a tenant.

Value parameters

parts

The values that together identify the cached item

Attributes

Returns

A 64-character hex string representing the hash