HayStackResponse
@JsonIgnoreProperties(ignoreUnknown = true) public class HayStackResponse
io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:130–206Hay Stack 响应,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.rag.integration.haystack.model 包。核心成员包括 getCode、setCode、getDocuments、setDocuments、getContextWindows、setContextWindows。
HayStack RAG API response model.
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.
** For Normal **
`{
"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
}
]
}
`
You can build your Haystack RAG server like this:
` @app.post("/retrieve")
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
}
`
** For SentenceWindowRetriever **
` {
"code": 0,
"context_windows": [
"Test Content 0 "
],
"context_documents": [
{
"id": "9e4cd66e14377767fdc6b9",
"content": "Test Content 1",
"meta": {
"source": "usr_90.txt",
"source_id": "1528904be8e57",
"page_number": 1,
"split_id": 21,
"split_idx_start": 11199,
"_split_overlap": [
{
"doc_id": "55ee242643b2439c8",
"range": [433, 570]
},
{
"doc_id": "cdc785a04643cbd",
"range": [0, 146]
}
]
}
}
]
}
`
You can build your Haystack RAG server like this:
` @app.post("/retrieve")
async def run_retriever(req: RetrieverRequest):
retrieved = bm25.run(
query=req.query,
top_k=req.top_k
)
retrieved_documents = retrieved["documents"]
sentence_window = SentenceWindowRetriever(document_store=doc_store)
result = sentence_window.run(
retrieved_documents=retrieved_documents,
window_size=req.window_size
)
return {
"code": 0,
"context_windows": result["context_windows"],
"context_documents": result["context_documents"],
"error": None
}
`
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Integer getCode() | 获取 `getCode`。 Returns the code. |
public void setCode(Integer code) | 设置 `setCode`。 Sets the code. |
public List<HayStackDocument> getDocuments() | 获取文档。 Returns the documents. |
public void setDocuments(List<HayStackDocument> documents) | 设置文档。 Sets the documents. |
public List<String> getContextWindows() | 获取 `getContextWindows`。 Returns the context windows. |
public void setContextWindows(List<String> contextWindows) | 设置 `setContextWindows`。 Sets the context windows. |
public List<HayStackDocument> getContextDocuments() | 获取上下文文档。 Returns the context documents. |
public void setContextDocuments(List<HayStackDocument> contextDocuments) | 设置上下文文档。 Sets the context documents. |
public String getError() | 获取错误。 Returns the error. |
public void setError(String error) | 设置错误。 Sets the error. |
public String toString() | 返回 `toString` 结果。 Returns the to string. |
方法详情Method Detail
getCode
public Integer getCode()
获取 getCode。
Returns the code.
Integerio/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:150–152setCode
public void setCode(Integer code)
设置 setCode。
Sets the code.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
code | Integer | code(类型 `Integer`)。The code. |
io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:154–156getDocuments
public List<HayStackDocument> getDocuments()
获取文档。
Returns the documents.
List<HayStackDocument>io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:158–160setDocuments
public void setDocuments(List<HayStackDocument> documents)
设置文档。
Sets the documents.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
documents | List<HayStackDocument> | 文档列表(类型 `List`)。The documents. |
io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:162–164getContextWindows
public List<String> getContextWindows()
获取 getContextWindows。
Returns the context windows.
List<String>io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:166–168setContextWindows
public void setContextWindows(List<String> contextWindows)
设置 setContextWindows。
Sets the context windows.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
contextWindows | List<String> | 上下文 Windows(类型 `List`)。The context windows. |
io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:170–172getContextDocuments
public List<HayStackDocument> getContextDocuments()
获取上下文文档。
Returns the context documents.
List<HayStackDocument>io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:174–176setContextDocuments
public void setContextDocuments(List<HayStackDocument> contextDocuments)
设置上下文文档。
Sets the context documents.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
contextDocuments | List<HayStackDocument> | 上下文文档(类型 `List`)。The context documents. |
io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:178–180getError
public String getError()
获取错误。
Returns the error.
Stringio/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:182–184setError
public void setError(String error)
设置错误。
Sets the error.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
error | String | 错误(类型 `String`)。The error. |
io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:186–188toString
public String toString()
返回 toString 结果。
Returns the to string.
Stringio/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:190–205