Class CassandraEmbeddingStore

java.lang.Object
dev.langchain4j.store.embedding.cassandra.CassandraEmbeddingStore
All Implemented Interfaces:
EmbeddingStore<TextSegment>

public class CassandraEmbeddingStore extends Object implements EmbeddingStore<TextSegment>
Implementation of EmbeddingStore using Cassandra.
See Also:
  • Field Details

    • embeddingTable

      protected com.dtsx.astra.sdk.cassio.MetadataVectorTable embeddingTable
      Represents an embedding table in Cassandra, it is a table with a vector column.
    • cassandraSession

      protected com.datastax.oss.driver.api.core.CqlSession cassandraSession
      Cassandra question.
  • Constructor Details

    • CassandraEmbeddingStore

      public CassandraEmbeddingStore(com.datastax.oss.driver.api.core.CqlSession session, String tableName, int dimension)
      Embedding Store.
      Parameters:
      session - cassandra Session
      tableName - table name
      dimension - 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 Session
      tableName - table name
      dimension - dimension
      metric - metric
  • Method Details

    • delete

      public void delete()
      Delete the table.
    • clear

      public void clear()
      Delete all rows.
    • builder

      public static CassandraEmbeddingStore.Builder builder()
    • builderAstra

      public static CassandraEmbeddingStore.BuilderAstra builderAstra()
    • add

      public String add(@NonNull @NonNull Embedding embedding)
      Add a new embedding to the store. - the row id is generated - text and metadata are not stored
      Specified by:
      add in interface EmbeddingStore<TextSegment>
      Parameters:
      embedding - representation of the list of floats
      Returns:
      newly created row id
    • add

      public String add(@NonNull @NonNull Embedding embedding, TextSegment textSegment)
      Add a new embedding to the store. - the row id is generated - text and metadata coming from the text Segment
      Specified by:
      add in interface EmbeddingStore<TextSegment>
      Parameters:
      embedding - representation of the list of floats
      textSegment - text content and metadata
      Returns:
      newly created row id
    • add

      public void add(@NonNull @NonNull String rowId, @NonNull @NonNull Embedding embedding)
      Add a new embedding to the store.
      Specified by:
      add in interface EmbeddingStore<TextSegment>
      Parameters:
      rowId - the row id
      embedding - representation of the list of floats
    • addAll

      public List<String> addAll(List<Embedding> embeddingList)
      Add multiple embeddings as a single action.
      Specified by:
      addAll in interface EmbeddingStore<TextSegment>
      Parameters:
      embeddingList - embeddings list
      Returns:
      list of new row if (same order as the input)
    • addAll

      public List<String> addAll(List<Embedding> embeddingList, List<TextSegment> textSegmentList)
      Add multiple embeddings as a single action.
      Specified by:
      addAll in interface EmbeddingStore<TextSegment>
      Parameters:
      embeddingList - embeddings
      textSegmentList - text segments
      Returns:
      list of new row if (same order as the input)
    • findRelevant

      public List<EmbeddingMatch<TextSegment>> findRelevant(Embedding embedding, int maxResults, double minScore)
      Search for relevant.
      Specified by:
      findRelevant in interface EmbeddingStore<TextSegment>
      Parameters:
      embedding - current embeddings
      maxResults - max number of result
      minScore - threshold
      Returns:
      list of matching elements
    • findRelevant

      public List<EmbeddingMatch<TextSegment>> findRelevant(Embedding embedding, int maxResults, double minScore, Metadata metadata)
      Similarity Search ANN based on the embedding.
      Parameters:
      embedding - vector
      maxResults - max number of results
      minScore - score minScore
      metadata - map key-value to build a metadata filter
      Returns:
      list of matching results