AS AgentScopeAPI 手册 / API Reference

HayStackResponse

@JsonIgnoreProperties(ignoreUnknown = true) public class HayStackResponse
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:130–206

Hay 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.

返回Returns Integer
返回数值结果。Returns a numeric result.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:150–152

setCode

public void setCode(Integer code)

设置 setCode。

Sets the code.

参数Parameters
名称Name类型Type说明Description
codeIntegercode(类型 `Integer`)。The code.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:154–156

getDocuments

public List<HayStackDocument> getDocuments()

获取文档。

Returns the documents.

返回Returns List<HayStackDocument>
返回列出。Returns list.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:158–160

setDocuments

public void setDocuments(List<HayStackDocument> documents)

设置文档。

Sets the documents.

参数Parameters
名称Name类型Type说明Description
documentsList<HayStackDocument>文档列表(类型 `List`)。The documents.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:162–164

getContextWindows

public List<String> getContextWindows()

获取 getContextWindows。

Returns the context windows.

返回Returns List<String>
返回列出。Returns list.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:166–168

setContextWindows

public void setContextWindows(List<String> contextWindows)

设置 setContextWindows。

Sets the context windows.

参数Parameters
名称Name类型Type说明Description
contextWindowsList<String>上下文 Windows(类型 `List`)。The context windows.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:170–172

getContextDocuments

public List<HayStackDocument> getContextDocuments()

获取上下文文档。

Returns the context documents.

返回Returns List<HayStackDocument>
返回列出。Returns list.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:174–176

setContextDocuments

public void setContextDocuments(List<HayStackDocument> contextDocuments)

设置上下文文档。

Sets the context documents.

参数Parameters
名称Name类型Type说明Description
contextDocumentsList<HayStackDocument>上下文文档(类型 `List`)。The context documents.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:178–180

getError

public String getError()

获取错误。

Returns the error.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:182–184

setError

public void setError(String error)

设置错误。

Sets the error.

参数Parameters
名称Name类型Type说明Description
errorString错误(类型 `String`)。The error.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:186–188

toString

public String toString()

返回 toString 结果。

Returns the to string.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/rag/integration/haystack/model/HayStackResponse.java:190–205
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.