Class QdrantVectorStore
java.lang.Object
org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
org.springframework.ai.vectorstore.qdrant.QdrantVectorStore
- All Implemented Interfaces:
Consumer<List<Document>>,DocumentWriter,VectorStore,VectorStoreRetriever,org.springframework.beans.factory.InitializingBean
public class QdrantVectorStore
extends 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, EmbeddingModel embeddingModel) Creates a new QdrantBuilder instance.createObservationContextBuilder(String operationName) Create a newVectorStoreObservationContext.Builderinstance.voidAdds a list of documents to the vector store.voidDeletes a list of documents by their IDs.protected voiddoDelete(Filter.Expression filterExpression) Template method for concrete implementations to provide filter-based deletion logic.doSimilaritySearch(SearchRequest request) Performs a similarity search on the vector store.<T> Optional<T> Returns the native client if available in this vector store implementation.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, getNameMethods inherited from interface org.springframework.ai.vectorstore.VectorStoreRetriever
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, 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 classAbstractObservationVectorStore- Parameters:
documents- The list of documents to be added.
-
doDelete
Deletes a list of documents by their IDs.- Specified by:
doDeletein classAbstractObservationVectorStore- Parameters:
documentIds- The list of document IDs to be deleted.
-
doDelete
Description copied from class:AbstractObservationVectorStoreTemplate method for concrete implementations to provide filter-based deletion logic.- Overrides:
doDeletein classAbstractObservationVectorStore- Parameters:
filterExpression- Filter expression to identify documents to delete
-
doSimilaritySearch
Performs a similarity search on the vector store.- Specified by:
doSimilaritySearchin classAbstractObservationVectorStore- 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
Description copied from class:AbstractObservationVectorStoreCreate a newVectorStoreObservationContext.Builderinstance.- Specified by:
createObservationContextBuilderin classAbstractObservationVectorStore- Parameters:
operationName- the operation name- Returns:
- the observation context builder
-
getNativeClient
Description copied from interface:VectorStoreReturns the native client if available in this vector store implementation. Note on usage: 1. Returns empty Optional when no native client is available 2. Due to Java type erasure, runtime type checking is not possible Example usage: When working with implementation with known native client: Optionalclient = vectorStore.getNativeClient(); Note: Using Optionalinvalid input: '<'?> will return the native client if one exists, rather than an empty Optional. For type safety, prefer using the specific client type. - Specified by:
getNativeClientin interfaceVectorStore- Type Parameters:
T- The type of the native client- Returns:
- Optional containing native client if available, empty Optional otherwise
-