Class CassandraEmbeddingStore
java.lang.Object
dev.langchain4j.store.embedding.cassandra.CassandraEmbeddingStore
- All Implemented Interfaces:
EmbeddingStore<TextSegment>
Implementation of
EmbeddingStore using Cassandra.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.datastax.oss.driver.api.core.CqlSessionCassandra question.protected com.dtsx.astra.sdk.cassio.MetadataVectorTableRepresents an embedding table in Cassandra, it is a table with a vector column. -
Constructor Summary
ConstructorsConstructorDescriptionCassandraEmbeddingStore(com.datastax.oss.driver.api.core.CqlSession session, String tableName, int dimension) Embedding Store.CassandraEmbeddingStore(com.datastax.oss.driver.api.core.CqlSession session, String tableName, int dimension, com.dtsx.astra.sdk.cassio.CassandraSimilarityMetric metric) Embedding Store. -
Method Summary
Modifier and TypeMethodDescriptionAdd a new embedding to the store.add(@NonNull Embedding embedding, TextSegment textSegment) Add a new embedding to the store.voidAdd a new embedding to the store.Add multiple embeddings as a single action.voidAdds multiple embeddings and their corresponding contents that have been embedded to the store.builder()voidclear()Delete all rows.voiddelete()Delete the table.findRelevant(Embedding embedding, int maxResults, double minScore) findRelevant(Embedding embedding, int maxResults, double minScore, Metadata metadata) Similarity Search ANN based on the embedding.com.datastax.oss.driver.api.core.CqlSessionsearch(EmbeddingSearchRequest request) Searches for the most similar (closest in the embedding space)Embeddings.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EmbeddingStore
addAll, generateIds, remove, removeAll, removeAll, removeAll
-
Field Details
-
embeddingTable
protected com.dtsx.astra.sdk.cassio.MetadataVectorTable embeddingTableRepresents an embedding table in Cassandra, it is a table with a vector column. -
cassandraSession
protected com.datastax.oss.driver.api.core.CqlSession cassandraSessionCassandra question.
-
-
Constructor Details
-
CassandraEmbeddingStore
public CassandraEmbeddingStore(com.datastax.oss.driver.api.core.CqlSession session, String tableName, int dimension) Embedding Store.- Parameters:
session- cassandra SessiontableName- table namedimension- dimension
-
CassandraEmbeddingStore
public CassandraEmbeddingStore(com.datastax.oss.driver.api.core.CqlSession session, String tableName, int dimension, com.dtsx.astra.sdk.cassio.CassandraSimilarityMetric metric) Embedding Store.- Parameters:
session- cassandra SessiontableName- table namedimension- dimensionmetric- metric
-
-
Method Details
-
delete
public void delete()Delete the table. -
clear
public void clear()Delete all rows. -
getCassandraSession
public com.datastax.oss.driver.api.core.CqlSession getCassandraSession() -
builder
-
builderAstra
-
add
Add a new embedding to the store. - the row id is generated - text and metadata are not stored- Specified by:
addin interfaceEmbeddingStore<TextSegment>- Parameters:
embedding- representation of the list of floats- Returns:
- newly created row id
-
add
Add a new embedding to the store. - the row id is generated - text and metadata coming from the text Segment- Specified by:
addin interfaceEmbeddingStore<TextSegment>- Parameters:
embedding- representation of the list of floatstextSegment- text content and metadata- Returns:
- newly created row id
-
add
Add a new embedding to the store.- Specified by:
addin interfaceEmbeddingStore<TextSegment>- Parameters:
rowId- the row idembedding- representation of the list of floats
-
addAll
Add multiple embeddings as a single action.- Specified by:
addAllin interfaceEmbeddingStore<TextSegment>- Parameters:
embeddingList- embeddings list- Returns:
- list of new row if (same order as the input)
-
addAll
public void addAll(List<String> ids, List<Embedding> embeddingList, List<TextSegment> textSegmentList) Description copied from interface:EmbeddingStoreAdds multiple embeddings and their corresponding contents that have been embedded to the store.- Specified by:
addAllin interfaceEmbeddingStore<TextSegment>- Parameters:
ids- A list of IDs associated with the added embeddings.embeddingList- A list of embeddings to be added to the store.textSegmentList- A list of original contents that were embedded.
-
search
Description copied from interface:EmbeddingStoreSearches for the most similar (closest in the embedding space)Embeddings.
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 allEmbeddingStoreimplementations supportFiltering.- Specified by:
searchin interfaceEmbeddingStore<TextSegment>- Parameters:
request- A request to search in anEmbeddingStore. Contains all search criteria.- Returns:
- An
EmbeddingSearchResultcontaining all foundEmbeddings.
-
findRelevant
public List<EmbeddingMatch<TextSegment>> findRelevant(Embedding embedding, int maxResults, double minScore) -
findRelevant
public List<EmbeddingMatch<TextSegment>> findRelevant(Embedding embedding, int maxResults, double minScore, Metadata metadata) Similarity Search ANN based on the embedding.- Parameters:
embedding- vectormaxResults- max number of resultsminScore- score minScoremetadata- map key-value to build a metadata filter- Returns:
- list of matching results
-