Class HayStackClient

java.lang.Object
io.agentscope.core.rag.integration.haystack.HayStackClient

public class HayStackClient extends Object
Client for interacting with HayStack Knowledge Base API.

This class wraps OkHttp client and provides reactive API methods for knowledge base operations. It handles HTTP request construction, error handling, and response parsing.

Example usage:


 HayStackConfig config = HayStackConfig.builder()
     .baseUrl(...)
     .topK(...)
     .build();

 HayStackClient client = new HayStackClient(config);
 HayStackResponse response = client.retrieve("query text", 10).block();
 
  • Constructor Details

  • Method Details

    • retrieve

      public reactor.core.publisher.Mono<HayStackResponse> retrieve(String query, Integer topK, Double scoreThreshold)
      Retrieve documents from HayStack knowledge base.

      This method calls the HayStack retrieval API to search for relevant document chunks.

      Since Haystack does not provide a standard REST API format, the API response of your custom-built Haystack RAG server should conform to the following format:

      
       {
         "code": 0,
         "documents": [
           {
             "id": "0fab3c1c6c433368",
             "content": "Test Content",
             "blob": null,
             "meta": {
               "file_path": "test.txt"
             },
             "score": 1.2303546667099,
             "embedding": [
               0.01008153147995472,
               -0.04555170238018036,
               -0.024434546008706093
             ],
             "sparse_embedding": null,
             "error": null
           }
         ]
       }
       

      In typical scenarios, you can build your Haystack RAG server like this:

      
       @app.post("/retrieve", response_model=HayStackResponse)
       async def retriever(req: Request):
           result = retriever.run(
               query=req.query,
               top_k=req.top_k,
           )
           documents = result["documents"]
      
           return {
               "code": 0,
               "documents": documents,
               "error": None
           }
       
      Parameters:
      query - the query text (required)
      topK - the number of documents to retrieve (optional, defaults to config value)
      Returns:
      a Mono emitting the retrieval response