Package dev.langchain4j.store.embedding
Interface EmbeddingStore<Embedded>
- Type Parameters:
Embedded
- The class of the object that has been embedded. Typically, this isTextSegment
.
- All Known Implementing Classes:
AbstractAzureAiSearchEmbeddingStore
,AstraDbEmbeddingStore
,AzureAiSearchContentRetriever
,AzureAiSearchEmbeddingStore
,AzureCosmosDbMongoVCoreEmbeddingStore
,AzureCosmosDbNoSqlEmbeddingStore
,CassandraEmbeddingStore
,ChromaEmbeddingStore
,CoherenceEmbeddingStore
,CouchbaseEmbeddingStore
,ElasticsearchEmbeddingStore
,InfinispanEmbeddingStore
,InMemoryEmbeddingStore
,MilvusEmbeddingStore
,MongoDbEmbeddingStore
,Neo4jEmbeddingStore
,OpenSearchEmbeddingStore
,OracleEmbeddingStore
,PgVectorEmbeddingStore
,PineconeEmbeddingStore
,QdrantEmbeddingStore
,RedisEmbeddingStore
,TablestoreEmbeddingStore
,VearchEmbeddingStore
,VespaEmbeddingStore
,WeaviateEmbeddingStore
public interface EmbeddingStore<Embedded>
Represents a store for embeddings, also known as a vector database.
-
Method Summary
Modifier and TypeMethodDescriptionAdds a given embedding to the store.Adds a given embedding and the corresponding content that has been embedded to the store.void
Adds a given embedding to the store.Adds multiple embeddings to the store.Adds multiple embeddings and their corresponding contents that have been embedded to the store.default List
<EmbeddingMatch<Embedded>> findRelevant
(Embedding referenceEmbedding, int maxResults) Deprecated, for removal: This API element is subject to removal in a future version.default List
<EmbeddingMatch<Embedded>> findRelevant
(Embedding referenceEmbedding, int maxResults, double minScore) Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usesearch(EmbeddingSearchRequest)
instead.default List
<EmbeddingMatch<Embedded>> findRelevant
(Object memoryId, Embedding referenceEmbedding, int maxResults) Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usesearch(EmbeddingSearchRequest)
instead.default List
<EmbeddingMatch<Embedded>> findRelevant
(Object memoryId, Embedding referenceEmbedding, int maxResults, double minScore) Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usesearch(EmbeddingSearchRequest)
instead.default void
Removes a single embedding from the store by ID.default void
Removes all embeddings from the store.default void
Removes all embeddings that match the specifiedFilter
from the store.default void
removeAll
(Collection<String> ids) Removes all embeddings that match the specified IDs from the store.default EmbeddingSearchResult
<Embedded> search
(EmbeddingSearchRequest request) Searches for the most similar (closest in the embedding space)Embedding
s.
-
Method Details
-
add
Adds a given embedding to the store.- Parameters:
embedding
- The embedding to be added to the store.- Returns:
- The auto-generated ID associated with the added embedding.
-
add
Adds a given embedding to the store.- Parameters:
id
- The unique identifier for the embedding to be added.embedding
- The embedding to be added to the store.
-
add
Adds a given embedding and the corresponding content that has been embedded to the store.- Parameters:
embedding
- The embedding to be added to the store.embedded
- Original content that was embedded.- Returns:
- The auto-generated ID associated with the added embedding.
-
addAll
Adds multiple embeddings to the store.- Parameters:
embeddings
- A list of embeddings to be added to the store.- Returns:
- A list of auto-generated IDs associated with the added embeddings.
-
addAll
Adds multiple embeddings and their corresponding contents that have been embedded to the store.- Parameters:
embeddings
- A list of embeddings to be added to the store.embedded
- A list of original contents that were embedded.- Returns:
- A list of auto-generated IDs associated with the added embeddings.
-
remove
Removes a single embedding from the store by ID.- Parameters:
id
- The unique ID of the embedding to be removed.
-
removeAll
Removes all embeddings that match the specified IDs from the store.- Parameters:
ids
- A collection of unique IDs of the embeddings to be removed.
-
removeAll
Removes all embeddings that match the specifiedFilter
from the store.- Parameters:
filter
- The filter to be applied to theMetadata
of theTextSegment
during removal. Only embeddings whoseTextSegment
'sMetadata
match theFilter
will be removed.
-
removeAll
default void removeAll()Removes all embeddings from the store. -
search
Searches for the most similar (closest in the embedding space)Embedding
s.
All search criteria are defined inside theEmbeddingSearchRequest
.
EmbeddingSearchRequest.filter()
can be used to filter by various metadata entries (e.g., user/memory ID). Please note that not allEmbeddingStore
implementations supportFilter
ing.- Parameters:
request
- A request to search in anEmbeddingStore
. Contains all search criteria.- Returns:
- An
EmbeddingSearchResult
containing all foundEmbedding
s.
-
findRelevant
@Deprecated(forRemoval=true) default List<EmbeddingMatch<Embedded>> findRelevant(Embedding referenceEmbedding, int maxResults) Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usesearch(EmbeddingSearchRequest)
instead.Finds the most relevant (closest in space) embeddings to the provided reference embedding. By default, minScore is set to 0, which means that the results may include embeddings with low relevance.- Parameters:
referenceEmbedding
- The embedding used as a reference. Returned embeddings should be relevant (closest) to this one.maxResults
- The maximum number of embeddings to be returned.- Returns:
- A list of embedding matches. Each embedding match includes a relevance score (derivative of cosine distance), ranging from 0 (not relevant) to 1 (highly relevant).
-
findRelevant
@Deprecated(forRemoval=true) default List<EmbeddingMatch<Embedded>> findRelevant(Embedding referenceEmbedding, int maxResults, double minScore) Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usesearch(EmbeddingSearchRequest)
instead.Finds the most relevant (closest in space) embeddings to the provided reference embedding.- Parameters:
referenceEmbedding
- The embedding used as a reference. Returned embeddings should be relevant (closest) to this one.maxResults
- The maximum number of embeddings to be returned.minScore
- The minimum relevance score, ranging from 0 to 1 (inclusive). Only embeddings with a score of this value or higher will be returned.- Returns:
- A list of embedding matches. Each embedding match includes a relevance score (derivative of cosine distance), ranging from 0 (not relevant) to 1 (highly relevant).
-
findRelevant
@Deprecated(forRemoval=true) default List<EmbeddingMatch<Embedded>> findRelevant(Object memoryId, Embedding referenceEmbedding, int maxResults) Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usesearch(EmbeddingSearchRequest)
instead.Finds the most relevant (closest in space) embeddings to the provided reference embedding. By default, minScore is set to 0, which means that the results may include embeddings with low relevance.- Parameters:
memoryId
- The memoryId used Distinguishing query requests from different users.referenceEmbedding
- The embedding used as a reference. Returned embeddings should be relevant (closest) to this one.maxResults
- The maximum number of embeddings to be returned.- Returns:
- A list of embedding matches. Each embedding match includes a relevance score (derivative of cosine distance), ranging from 0 (not relevant) to 1 (highly relevant).
-
findRelevant
@Deprecated(forRemoval=true) default List<EmbeddingMatch<Embedded>> findRelevant(Object memoryId, Embedding referenceEmbedding, int maxResults, double minScore) Deprecated, for removal: This API element is subject to removal in a future version.as of 0.31.0, usesearch(EmbeddingSearchRequest)
instead.Finds the most relevant (closest in space) embeddings to the provided reference embedding.- Parameters:
memoryId
- The memoryId used Distinguishing query requests from different users.referenceEmbedding
- The embedding used as a reference. Returned embeddings should be relevant (closest) to this one.maxResults
- The maximum number of embeddings to be returned.minScore
- The minimum relevance score, ranging from 0 to 1 (inclusive). Only embeddings with a score of this value or higher will be returned.- Returns:
- A list of embedding matches. Each embedding match includes a relevance score (derivative of cosine distance), ranging from 0 (not relevant) to 1 (highly relevant).
-
search(EmbeddingSearchRequest)
instead.