AS AgentScopeAPI 手册 / API Reference

BailianKnowledge

public class BailianKnowledge implements Knowledge
源码Source io/agentscope/core/rag/integration/bailian/BailianKnowledge.java:87–390

Bailian 知识库,把私有文档转化为可检索的知识。位于 io.agentscope.core.rag.integration.bailian 包,实现 Knowledge。核心成员包括 addDocuments、retrieve、getIndexId、getClient、builder。

Bailian Cloud Knowledge Base implementation.

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

Key features:

  • Cloud-hosted knowledge base (no local infrastructure needed)

  • Automatic document parsing and embedding by Bailian service

  • Enterprise-grade search with reranking and filtering

  • Supports structured, unstructured, and image knowledge bases

Example usage:

`// 1. Configure Bailian connection
BailianConfig config = BailianConfig.builder()
.accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
.accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
.workspaceId("llm-xxx")
.indexId("mymxbdxxxx")
.build();

// 2. Create knowledge base instance
BailianKnowledge knowledge = BailianKnowledge.builder()
.config(config)
.build();

// 3. Retrieve documents
RetrieveConfig retrieveConfig = RetrieveConfig.builder()
.limit(5)
.scoreThreshold(0.5)
.build();

List<Document> results = knowledge.retrieve("query text", retrieveConfig).block();

// 4. Use with agents via KnowledgeRetrievalTools
KnowledgeRetrievalTools tools = new KnowledgeRetrievalTools(knowledge);
Toolkit toolkit = new Toolkit();
toolkit.registerObject(tools);

ReActAgent agent = ReActAgent.builder()
.name("Assistant")
.model(chatModel)
.toolkit(toolkit)
.build();
`

Note: Currently, only the retrieve operation is supported via API. Document upload and management must be performed through the Bailian console or will be supported in future releases.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
BailianKnowledge的构建器。
Builder for BailianKnowledge.

方法摘要Method Summary

方法Method说明Description
public Mono<Void> addDocuments(List<Document> documents)
添加文档。
Adds documents to the knowledge base.
public Mono<List<Document>> retrieve(String query, RetrieveConfig config)
按查询检索相关文档。
Retrieves relevant documents based on a query.
public String getIndexId()
获取知识库基类索引标识。
Gets the knowledge base index ID.
public BailianClient getClient()
获取客户端。
Gets the Bailian API client.
public static Builder builder()
static
创建新的构建器用于 BailianKnowledge。
Creates a new builder for BailianKnowledge.

方法详情Method Detail

addDocuments

public Mono<Void> addDocuments(List<Document> documents)

添加文档。

Adds documents to the knowledge base.

参数Parameters
名称Name类型Type说明Description
documentsList<Document>文档到添加的列出。the list of documents to add
返回Returns Mono<Void>
返回Mono。a Mono that completes with an error indicating the operation is not supported
源码Source io/agentscope/core/rag/integration/bailian/BailianKnowledge.java:130–137

retrieve

public Mono<List<Document>> retrieve(String query, RetrieveConfig config)

按查询检索相关文档。

Retrieves relevant documents based on a query.

参数Parameters
名称Name类型Type说明Description
queryString搜索查询文本。the search query text
configRetrieveConfig检索配置(限制,分数阈值,会话历史)。the retrieval configuration (limit, score threshold, conversation history)
返回Returns Mono<List<Document>>
返回Mono>。a Mono that emits a list of relevant Document objects, sorted by relevance
源码Source io/agentscope/core/rag/integration/bailian/BailianKnowledge.java:162–215

getIndexId

public String getIndexId()

获取知识库基类索引标识。

Gets the knowledge base index ID.

返回Returns String
索引标识。the index ID
源码Source io/agentscope/core/rag/integration/bailian/BailianKnowledge.java:276–278

getClient

public BailianClient getClient()

获取客户端。

Gets the Bailian API client.

返回Returns BailianClient
客户端。the client
源码Source io/agentscope/core/rag/integration/bailian/BailianKnowledge.java:285–287

builder

public static Builder builder()
static

创建新的构建器用于 BailianKnowledge。

Creates a new builder for BailianKnowledge.

返回Returns Builder
一种新的构建器实例。a new Builder instance
源码Source io/agentscope/core/rag/integration/bailian/BailianKnowledge.java:294–296

嵌套类详情Nested Class Detail

Builder

public static class Builder

BailianKnowledge的构建器。位于 io.agentscope.core.rag.integration.bailian 包。核心成员包括 config、client、indexId、build。

Builder for BailianKnowledge.

基于官方固定版本源码静态生成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.