Class QdrantStore

java.lang.Object
io.agentscope.core.rag.store.QdrantStore
All Implemented Interfaces:
VDBStoreBase, AutoCloseable

public class QdrantStore extends Object implements VDBStoreBase, AutoCloseable
Qdrant vector database store implementation.

This class provides an interface for storing and searching vectors using Qdrant, a production-ready vector database. It implements the VDBStoreBase interface to provide a unified API for vector storage operations.

In Qdrant, we use the payload field to store the metadata, including the document ID, chunk ID, and original content.

This implementation uses the Qdrant Java SDK (io.qdrant:client). To use this class, add the following dependency:


 <dependency>
     <groupId>io.qdrant</groupId>
     <artifactId>client</artifactId>
     <version>1.15.0</version>
     <scope>provided</scope>
 </dependency>
 

Example usage:


 // Using builder with TLS and compatibility options (recommended)
 try (QdrantStore store = QdrantStore.builder()
         .location("http://localhost:6333")
         .collectionName("my_collection")
         .dimensions(1024)
         .apiKey("my-api-key")
         .useTransportLayerSecurity(true)
         .checkCompatibility(false)
         .build()) {
     store.add(document).block();
     List<Document> results = store.search(queryEmbedding, 5).block();
     // Store is automatically closed here
 }

 // Using static factory method (simpler, uses defaults)
 try (QdrantStore store = QdrantStore.create("http://localhost:6333", "my_collection", 1024)) {
     store.add(document).block();
     List<Document> results = store.search(queryEmbedding, 5).block();
 }
 

Note: The location parameter can be:

  • HTTP URL: "http://localhost:6333" - will use gRPC on port 6334
  • gRPC URL: "localhost:6334" - direct gRPC connection
  • Local path: "file:///path/to/qdrant" - local Qdrant instance
  • Memory mode: ":memory:" - in-memory Qdrant (requires local Qdrant)
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder for creating QdrantStore instances with fluent configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    reactor.core.publisher.Mono<Void>
    add(List<io.agentscope.core.rag.model.Document> documents)
    Adds multiple documents to the store.
    Creates a new builder for constructing QdrantStore instances.
    void
    Closes the Qdrant client and releases all resources.
    reactor.core.publisher.Mono<Boolean>
    Deletes a document from the store (optional).
    Gets the API key (if set).
    io.qdrant.client.QdrantClient
    Gets the underlying Qdrant client for advanced operations.
    Gets the collection name.
    int
    Gets the vector dimensions.
    io.qdrant.client.QdrantGrpcClient
    Gets the underlying gRPC client for low-level operations.
    Gets the Qdrant server location.
    boolean
    Checks if this store has been closed.
    reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>>
    search(SearchDocumentDto searchDocumentDto)
    Searches for similar documents.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • add

      public reactor.core.publisher.Mono<Void> add(List<io.agentscope.core.rag.model.Document> documents)
      Description copied from interface: VDBStoreBase
      Adds multiple documents to the store.

      All documents must have embedding vectors set. The store will persist both the vectors and the document metadata/payloads.

      This method supports batch operations for efficiency. Implementations should handle batch insertion optimally.

      Specified by:
      add in interface VDBStoreBase
      Parameters:
      documents - the list of documents to store (all must have embeddings set)
      Returns:
      a Mono that completes when all documents are stored
    • search

      public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> search(SearchDocumentDto searchDocumentDto)
      Description copied from interface: VDBStoreBase
      Searches for similar documents.

      This method performs vector similarity search and returns the most similar documents. Results include the document metadata and similarity scores. Optionally, embeddings may also be included in the results (implementation-dependent).

      Specified by:
      search in interface VDBStoreBase
      Parameters:
      searchDocumentDto - the search document DTO
      Returns:
      a Mono that emits a list of Document objects with scores set, sorted by similarity (descending)
    • delete

      public reactor.core.publisher.Mono<Boolean> delete(String id)
      Description copied from interface: VDBStoreBase
      Deletes a document from the store (optional).

      Default implementation throws UnsupportedOperationException. Vector stores that support deletion should override this method.

      Specified by:
      delete in interface VDBStoreBase
      Parameters:
      id - the document ID (UUID string) to delete
      Returns:
      a Mono that emits true if the deletion was successful, false otherwise
    • getClient

      public io.qdrant.client.QdrantClient getClient() throws VectorStoreException
      Gets the underlying Qdrant client for advanced operations.

      This method provides access to the Qdrant client for users who need to perform operations beyond the standard VDBStoreBase interface, such as:

      • Custom index configuration
      • Advanced filtering and faceting
      • Collection management
      • Batch operations
      Returns:
      the QdrantClient instance
      Throws:
      VectorStoreException - if the store has been closed
    • getGrpcClient

      public io.qdrant.client.QdrantGrpcClient getGrpcClient() throws VectorStoreException
      Gets the underlying gRPC client for low-level operations.

      This provides direct access to the gRPC client for advanced users who need maximum control over Qdrant operations.

      Returns:
      the QdrantGrpcClient instance
      Throws:
      VectorStoreException - if the store has been closed
    • getLocation

      public String getLocation()
      Gets the Qdrant server location.
      Returns:
      the location
    • getCollectionName

      public String getCollectionName()
      Gets the collection name.
      Returns:
      the collection name
    • getDimensions

      public int getDimensions()
      Gets the vector dimensions.
      Returns:
      the dimensions
    • getApiKey

      public String getApiKey()
      Gets the API key (if set).
      Returns:
      the API key, or null if not set
    • close

      public void close()
      Closes the Qdrant client and releases all resources.

      This method closes both the QdrantClient and the underlying QdrantGrpcClient, releasing all gRPC connections and associated resources. This method is idempotent and can be called multiple times safely.

      After closing, all operations on this store will fail with a VectorStoreException. It's recommended to use try-with-resources for automatic resource management:

      
       try (QdrantStore store = new QdrantStore("http://localhost:6333", "collection", 1024)) {
           store.add(1L, embedding).block();
           // Store is automatically closed here
       }
       
      Specified by:
      close in interface AutoCloseable
    • isClosed

      public boolean isClosed()
      Checks if this store has been closed.
      Returns:
      true if the store has been closed, false otherwise
    • builder

      public static QdrantStore.Builder builder()
      Creates a new builder for constructing QdrantStore instances.
      Returns:
      a new builder instance