Class HayStackKnowledge

java.lang.Object
io.agentscope.core.rag.integration.haystack.HayStackKnowledge
All Implemented Interfaces:
io.agentscope.core.rag.Knowledge

public class HayStackKnowledge extends Object implements io.agentscope.core.rag.Knowledge
HayStack RAG Knowledge Base implementation.

This class provides integration with HayStack Knowledge Base service, implementing the Knowledge interface to enable seamless RAG (Retrieval-Augmented Generation) capabilities with HayStack-hosted knowledge bases.

Key features:

  • Built on HayStack RAG with end-to-end retrieval, ranking, and generation pipelines
  • Local or remote HayStack deployment support
  • Compatible with Bailian and Dify RAG plugins (same Knowledge interface)

Functional Scope: This plugin focuses on retrieval capabilities only, similar to Bailian and Dify RAG plugins. Document management (upload/delete/update) should be performed via HayStack RAG server.

Example usage:


 HayStackConfig config = HayStackConfig.builder()
     .baseUrl("http://localhost:8080")
     .topK(10)
     .build();

 HayStackKnowledge knowledge = HayStackKnowledge.builder()
     .config(config)
     .build();

 // Retrieve documents
 List<Document> docs = knowledge.retrieve("What is AI?", retrieveConfig).block();

 // Use with Agent
 ReActAgent agent = ReActAgent.builder()
     .knowledge(knowledge)
     .ragMode(RAGMode.AGENTIC)
     .build();
 

Note: Document management is not supported via this plugin. Please use HayStack server to upload, delete, and manage documents. This design ensures compatibility with Bailian and Dify RAG plugins and keeps the plugin focused.

  • Method Details

    • builder

      public static HayStackKnowledge.Builder builder()
    • addDocuments

      public reactor.core.publisher.Mono<Void> addDocuments(List<io.agentscope.core.rag.model.Document> documents)
      Adds documents to the Haystack knowledge base.

      Note: This operation is not supported. Document ingestion and indexing are managed by the Haystack service itself.

      To add or update documents:

      1. Prepare source files in the configured data directory
      2. Restart or re-run the Haystack indexing pipeline
      3. Documents will be indexed into the document store (e.g. Chroma)
      4. Indexed documents become available for retrieval via this API

      This design keeps document management and retrieval responsibilities clearly separated and avoids inconsistent indexing states.

      Specified by:
      addDocuments in interface io.agentscope.core.rag.Knowledge
      Parameters:
      documents - the list of documents to add
      Returns:
      a Mono that completes with an error indicating the operation is not supported
    • retrieve

      public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> retrieve(String query, io.agentscope.core.rag.model.RetrieveConfig config)
      Retrieve documents from the HayStack knowledge base.

      This method searches the HayStack dataset for documents relevant to the given query. The results support filtering by score.

      Features:

      • Vector similarity search
      • Retrieve the context surrounding relevant sentences.
      • Configurable top-K results
      • Similarity threshold filtering

      Note: Unlike some other RAG systems, HayStack RAG's retrieve-document API does not support:

      • ❌ Conversation history for context-aware retrieval
      • ❌ Built-in reranking
      Specified by:
      retrieve in interface io.agentscope.core.rag.Knowledge
      Parameters:
      query - the query text (required)
      config - the retrieval configuration (limit, score)
      Returns:
      a Mono emitting the list of retrieved documents, sorted by relevance