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, 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
  • Field Details

  • Constructor Details

  • 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

      public void doAdd(List<Document> documents)
      Adds a list of documents to the vector store.
      Specified by:
      doAdd in class AbstractObservationVectorStore
      Parameters:
      documents - The list of documents to be added.
    • doDelete

      public void doDelete(List<String> documentIds)
      Deletes a list of documents by their IDs.
      Specified by:
      doDelete in class AbstractObservationVectorStore
      Parameters:
      documentIds - The list of document IDs to be deleted.
    • doDelete

      protected void doDelete(Filter.Expression filterExpression)
      Description copied from class: AbstractObservationVectorStore
      Template method for concrete implementations to provide filter-based deletion logic.
      Overrides:
      doDelete in class AbstractObservationVectorStore
      Parameters:
      filterExpression - Filter expression to identify documents to delete
    • doSimilaritySearch

      public List<Document> doSimilaritySearch(SearchRequest request)
      Performs a similarity search on the vector store.
      Specified by:
      doSimilaritySearch in class AbstractObservationVectorStore
      Parameters:
      request - The SearchRequest object containing the query and other search parameters.
      Returns:
      A list of documents that are similar to the query.
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • createObservationContextBuilder

      public VectorStoreObservationContext.Builder createObservationContextBuilder(String operationName)
      Description copied from class: AbstractObservationVectorStore
      Specified by:
      createObservationContextBuilder in class AbstractObservationVectorStore
      Parameters:
      operationName - the operation name
      Returns:
      the observation context builder
    • getNativeClient

      public <T> Optional<T> getNativeClient()
      Description copied from interface: VectorStore
      Returns 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: Optional client = vectorStore.getNativeClient(); Note: Using Optional<?> will return the native client if one exists, rather than an empty Optional. For type safety, prefer using the specific client type.
      Specified by:
      getNativeClient in interface VectorStore
      Type Parameters:
      T - The type of the native client
      Returns:
      Optional containing native client if available, empty Optional otherwise