Package com.tnsai.llm.cache
Class HashEmbeddingProvider
java.lang.Object
com.tnsai.llm.cache.HashEmbeddingProvider
- All Implemented Interfaces:
EmbeddingProvider
Simple hash-based embedding provider for testing and development.
This provider creates pseudo-embeddings by hashing the input text. It's NOT suitable for production semantic search, but useful for:
- Unit testing cache functionality
- Development without API keys
- Exact-match caching scenarios
Limitations
Hash-based embeddings only match identical strings. For true semantic similarity (where "How are you?" matches "How're you doing?"), use a real embedding model like OpenAI or sentence-transformers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloat[]Generates an embedding vector for the given text.intReturns the dimension of the embedding vectors.Returns the name of the embedding model.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.llm.cache.EmbeddingProvider
embed, embedBatch, embedBatch
-
Constructor Details
-
HashEmbeddingProvider
public HashEmbeddingProvider() -
HashEmbeddingProvider
public HashEmbeddingProvider(int dimension)
-
-
Method Details
-
embed
Description copied from interface:EmbeddingProviderGenerates an embedding vector for the given text.- Specified by:
embedin interfaceEmbeddingProvider- Parameters:
text- The text to embed- Returns:
- A float array representing the embedding vector
-
getDimension
public int getDimension()Description copied from interface:EmbeddingProviderReturns the dimension of the embedding vectors.- Specified by:
getDimensionin interfaceEmbeddingProvider
-
getModelName
Description copied from interface:EmbeddingProviderReturns the name of the embedding model.- Specified by:
getModelNamein interfaceEmbeddingProvider
-