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

Source
CacheKeyGenerator.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def embeddingKey(text: String, model: ModelName, 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

Source
CacheKeyGenerator.scala
def embeddingKey(text: String, request: EmbeddingRequest): String

The default embedding cache key for one input text of request: embeddingKey of the text, the request's model name and its purpose. This is the shape of CachedEmbeddingClient's key function, which is given the whole request so that a key of your own can use anything the request carries.

The default embedding cache key for one input text of request: embeddingKey of the text, the request's model name and its purpose. This is the shape of CachedEmbeddingClient's key function, which is given the whole request so that a key of your own can use anything the request carries.

Value parameters

request

The request the text is embedded by

text

One of the request's input texts

Attributes

Returns

A 64-character hex string representing the hash

Source
CacheKeyGenerator.scala
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

Source
CacheKeyGenerator.scala