Class HayStackKnowledge
- All Implemented Interfaces:
io.agentscope.core.rag.Knowledge
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.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>addDocuments(List<io.agentscope.core.rag.model.Document> documents) Adds documents to the Haystack knowledge base.static HayStackKnowledge.Builderbuilder()reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>>Retrieve documents from the HayStack knowledge base.
-
Method Details
-
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:
- Prepare source files in the configured data directory
- Restart or re-run the Haystack indexing pipeline
- Documents will be indexed into the document store (e.g. Chroma)
- 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:
addDocumentsin interfaceio.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:
retrievein interfaceio.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
-