Class ElasticsearchStore

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

public class ElasticsearchStore extends Object implements VDBStoreBase, AutoCloseable
Elasticsearch vector database store implementation.

This class provides an interface for storing and searching vectors using Elasticsearch. It uses the official elasticsearch-java client.

The implementation uses the dense_vector field type for storing embeddings and kNN search for retrieval.

Example usage:


 // Using builder with authentication
 try (ElasticsearchStore store = ElasticsearchStore.builder()
 .url("http://localhost:9200")
 .indexName("my_rag_index")
 .dimensions(1024)
 .username("elastic")
 .password("changeme")
 .build()) {

 store.add(document).block();
 List<Document> results = store.search(queryEmbedding, 5, 0.7).block();
 }
 
  • Method Details

    • add

      public reactor.core.publisher.Mono<Void> add(List<io.agentscope.core.rag.model.Document> documents)
      Adds a list of documents to the Elasticsearch index.
      Specified by:
      add in interface VDBStoreBase
      Parameters:
      documents - the list of documents to add
      Returns:
      a Mono that completes when the operation is finished
    • search

      public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> search(SearchDocumentDto searchDocumentDto)
      Searches for documents in the Elasticsearch index matching the query embedding.
      Specified by:
      search in interface VDBStoreBase
      Parameters:
      searchDocumentDto - the search criteria containing query embedding, limit, and score threshold
      Returns:
      a Mono containing the list of matching documents
    • delete

      public reactor.core.publisher.Mono<Boolean> delete(String id)
      Deletes a document from the Elasticsearch index by its ID.
      Specified by:
      delete in interface VDBStoreBase
      Parameters:
      id - the ID of the document to delete
      Returns:
      a Mono containing true if the document was deleted, false if not found
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • builder

      public static ElasticsearchStore.Builder builder()
      Creates a new builder for ElasticsearchStore.
      Returns:
      a new Builder instance