Class QdrantVectorStore
java.lang.Object
org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
org.springframework.ai.vectorstore.qdrant.QdrantVectorStore
- All Implemented Interfaces:
Consumer<List<org.springframework.ai.document.Document>>,org.springframework.ai.document.DocumentWriter,org.springframework.ai.vectorstore.VectorStore,org.springframework.beans.factory.InitializingBean
public class QdrantVectorStore
extends org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
implements org.springframework.beans.factory.InitializingBean
Qdrant vectorStore implementation. This store supports creating, updating, deleting,
and similarity searching of documents in a Qdrant collection.
The store uses Qdrant's vector search functionality to persist and query vector embeddings along with their associated document content and metadata. The implementation leverages Qdrant's HNSW (Hierarchical Navigable Small World) algorithm for efficient k-NN search operations.
Features:
- Automatic schema initialization with configurable collection creation
- Support for cosine similarity distance metric
- Metadata filtering using Qdrant's filter expressions
- Configurable similarity thresholds for search results
- Batch processing support with configurable strategies
- Observation and metrics support through Micrometer
Basic usage example:
QdrantVectorStore vectorStore = QdrantVectorStore.builder(qdrantClient)
.embeddingModel(embeddingModel)
.initializeSchema(true)
.build();
// Add documents
vectorStore.add(List.of(
new Document("content1", Map.of("key1", "value1")),
new Document("content2", Map.of("key2", "value2"))
));
// Search with filters
List<Document> results = vectorStore.similaritySearch(
SearchRequest.query("search text")
.withTopK(5)
.withSimilarityThreshold(0.7)
.withFilterExpression("key1 == 'value1'")
);
Advanced configuration example:
QdrantVectorStore vectorStore = QdrantVectorStore.builder(qdrantClient, embeddingModel)
.collectionName("custom-collection")
.initializeSchema(true)
.batchingStrategy(new TokenCountBatchingStrategy())
.observationRegistry(observationRegistry)
.customObservationConvention(customConvention)
.build();
Requirements:
- Running Qdrant instance accessible via gRPC
- Collection with vector size matching the embedding model dimensions
- Since:
- 1.0.0
- Author:
- Anush Shetty, Christian Tzolov, EddĂș MelĂ©ndez, Josh Long, Soby Chacko, Thomas Vitale
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating instances ofQdrantVectorStore. -
Field Summary
FieldsFields inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
batchingStrategy, embeddingModel -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected constructor for creating a QdrantVectorStore instance using the builder pattern. -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic QdrantVectorStore.Builderbuilder(io.qdrant.client.QdrantClient qdrantClient, org.springframework.ai.embedding.EmbeddingModel embeddingModel) Creates a new QdrantBuilder instance.org.springframework.ai.vectorstore.observation.VectorStoreObservationContext.BuildercreateObservationContextBuilder(String operationName) voidAdds a list of documents to the vector store.voidDeletes a list of documents by their IDs.protected voiddoDelete(org.springframework.ai.vectorstore.filter.Filter.Expression filterExpression) List<org.springframework.ai.document.Document>doSimilaritySearch(org.springframework.ai.vectorstore.SearchRequest request) Performs a similarity search on the vector store.<T> Optional<T>Methods inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
add, delete, delete, similaritySearchMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.document.DocumentWriter
writeMethods inherited from interface org.springframework.ai.vectorstore.VectorStore
accept, delete, getName, similaritySearch
-
Field Details
-
DEFAULT_COLLECTION_NAME
- See Also:
-
-
Constructor Details
-
QdrantVectorStore
Protected constructor for creating a QdrantVectorStore instance using the builder pattern.- Parameters:
builder- theQdrantVectorStore.Buildercontaining all configuration settings- Throws:
IllegalArgumentException- if qdrant client is missing- Since:
- 1.0.0
- See Also:
-
-
Method Details
-
builder
public static QdrantVectorStore.Builder builder(io.qdrant.client.QdrantClient qdrantClient, org.springframework.ai.embedding.EmbeddingModel embeddingModel) Creates a new QdrantBuilder instance. This is the recommended way to instantiate a QdrantVectorStore.- Parameters:
qdrantClient- the client for interfacing with Qdrant- Returns:
- a new QdrantBuilder instance
-
doAdd
Adds a list of documents to the vector store.- Specified by:
doAddin classorg.springframework.ai.vectorstore.observation.AbstractObservationVectorStore- Parameters:
documents- The list of documents to be added.
-
doDelete
Deletes a list of documents by their IDs.- Specified by:
doDeletein classorg.springframework.ai.vectorstore.observation.AbstractObservationVectorStore- Parameters:
documentIds- The list of document IDs to be deleted.
-
doDelete
protected void doDelete(org.springframework.ai.vectorstore.filter.Filter.Expression filterExpression) - Overrides:
doDeletein classorg.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
-
doSimilaritySearch
public List<org.springframework.ai.document.Document> doSimilaritySearch(org.springframework.ai.vectorstore.SearchRequest request) Performs a similarity search on the vector store.- Specified by:
doSimilaritySearchin classorg.springframework.ai.vectorstore.observation.AbstractObservationVectorStore- Parameters:
request- TheSearchRequestobject containing the query and other search parameters.- Returns:
- A list of documents that are similar to the query.
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
createObservationContextBuilder
public org.springframework.ai.vectorstore.observation.VectorStoreObservationContext.Builder createObservationContextBuilder(String operationName) - Specified by:
createObservationContextBuilderin classorg.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
-
getNativeClient
- Specified by:
getNativeClientin interfaceorg.springframework.ai.vectorstore.VectorStore
-