Class CassandraVectorStore
java.lang.Object
org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
org.springframework.ai.vectorstore.CassandraVectorStore
- All Implemented Interfaces:
AutoCloseable
,Consumer<List<Document>>
,DocumentWriter
,VectorStore
The CassandraVectorStore is for managing and querying vector data in an Apache
Cassandra db. It offers functionalities like adding, deleting, and performing
similarity searches on documents.
The store utilizes CQL to index and search vector data. It allows for custom metadata
fields in the documents to be stored alongside the vector and content data.
This class requires a CassandraVectorStoreConfig configuration object for
initialization, which includes settings like connection details, index name, column
names, etc. It also requires an EmbeddingModel to convert documents into embeddings
before storing them.
A schema matching the configuration is automatically created if it doesn't exist.
Missing columns and indexes in existing tables will also be automatically created.
Disable this with the CassandraVectorStoreConfig#disallowSchemaChanges().
This class is designed to work with brand new tables that it creates for you, or on top
of existing Cassandra tables. The latter is appropriate when wanting to keep data in
place, creating embeddings next to it, and performing vector similarity searches
in-situ.
Instances of this class are not dynamic against server-side schema changes. If you
change the schema server-side you need a new CassandraVectorStore instance.
When adding documents with the method
AbstractObservationVectorStore.add(List<Document>)
it first calls
embeddingModel to create the embeddings. This is slow. Configure
CassandraVectorStoreConfig.Builder.withFixedThreadPoolExecutorSize(int)
accordingly to improve performance so embeddings are created and the documents are
added concurrently. The default concurrency is 16
(CassandraVectorStoreConfig.DEFAULT_ADD_CONCURRENCY
). Remote transformers
probably want higher concurrency, and local transformers may need lower concurrency.
This concurrency limit does not need to be higher than the max parallel calls made to
the AbstractObservationVectorStore.add(List<Document>)
method multiplied by the list size. This setting can
also serve as a protecting throttle against your embedding model.- Since:
- 1.0.0
- Author:
- Mick Semb Wever, Christian Tzolov, Thomas Vitale, Soby Chacko
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Indexes are automatically created with COSINE.Nested classes/interfaces inherited from interface org.springframework.ai.vectorstore.VectorStore
VectorStore.Builder<T extends VectorStore.Builder<T>>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCassandraVectorStore
(CassandraVectorStoreConfig conf, EmbeddingModel embeddingModel) CassandraVectorStore
(CassandraVectorStoreConfig conf, EmbeddingModel embeddingModel, io.micrometer.observation.ObservationRegistry observationRegistry, VectorStoreObservationConvention customObservationConvention, BatchingStrategy batchingStrategy) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
createObservationContextBuilder
(String operationName) Create a newVectorStoreObservationContext.Builder
instance.void
Perform the actual add operation.Perform the actual delete operation.doSimilaritySearch
(SearchRequest request) Perform the actual similarity search operation.Methods inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
add, delete, similaritySearch
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.ai.document.DocumentWriter
write
Methods inherited from interface org.springframework.ai.vectorstore.VectorStore
accept, getName, similaritySearch
-
Field Details
-
DRIVER_PROFILE_UPDATES
- See Also:
-
DRIVER_PROFILE_SEARCH
- See Also:
-
-
Constructor Details
-
CassandraVectorStore
-
CassandraVectorStore
public CassandraVectorStore(CassandraVectorStoreConfig conf, EmbeddingModel embeddingModel, io.micrometer.observation.ObservationRegistry observationRegistry, VectorStoreObservationConvention customObservationConvention, BatchingStrategy batchingStrategy)
-
-
Method Details
-
doAdd
Description copied from class:AbstractObservationVectorStore
Perform the actual add operation.- Specified by:
doAdd
in classAbstractObservationVectorStore
- Parameters:
documents
- the documents to add
-
doDelete
Description copied from class:AbstractObservationVectorStore
Perform the actual delete operation.- Specified by:
doDelete
in classAbstractObservationVectorStore
- Parameters:
idList
- the list of document IDs to delete- Returns:
- true if the documents were successfully deleted
-
doSimilaritySearch
Description copied from class:AbstractObservationVectorStore
Perform the actual similarity search operation.- Specified by:
doSimilaritySearch
in classAbstractObservationVectorStore
- Parameters:
request
- the search request- Returns:
- the list of documents that match the query request conditions
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
createObservationContextBuilder
Description copied from class:AbstractObservationVectorStore
Create a newVectorStoreObservationContext.Builder
instance.- Specified by:
createObservationContextBuilder
in classAbstractObservationVectorStore
- Parameters:
operationName
- the operation name- Returns:
- the observation context builder
-