Bedrock Knowledge Base Retriever
BedrockKBRetrieverTool
Section titled “BedrockKBRetrieverTool”BedrockKBRetrieverTool 让 CrewAI agents 能够使用自然语言查询从 Amazon Bedrock Knowledge Bases 检索信息。
uv pip install 'crewai[tools]'- 已配置 AWS 凭据(通过环境变量或 AWS CLI)
boto3和python-dotenv包- 可访问 Amazon Bedrock Knowledge Base
下面展示如何在 CrewAI agent 中使用该工具:
from crewai import Agent, Task, Crewfrom crewai_tools.aws.bedrock.knowledge_base.retriever_tool import BedrockKBRetrieverTool
# Initialize the toolkb_tool = BedrockKBRetrieverTool( knowledge_base_id="your-kb-id", number_of_results=5)
# Create a CrewAI agent that uses the toolresearcher = Agent( role='Knowledge Base Researcher', goal='Find information about company policies', backstory='I am a researcher specialized in retrieving and analyzing company documentation.', tools=[kb_tool], verbose=True)
# Create a task for the agentresearch_task = Task( description="Find our company's remote work policy and summarize the key points.", agent=researcher)
# Create a crew with the agentcrew = Crew( agents=[researcher], tasks=[research_task], verbose=2)
# Run the crewresult = crew.kickoff()print(result)| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| knowledge_base_id | str | Yes | None | 知识库的唯一标识符(0-10 个字母数字字符) |
| number_of_results | int | No | 5 | 返回结果的最大数量 |
| retrieval_configuration | dict | No | None | 针对知识库查询的自定义配置 |
| guardrail_configuration | dict | No | None | 内容过滤设置 |
| next_token | str | No | None | 用于分页的 token |
BEDROCK_KB_ID=your-knowledge-base-id # Alternative to passing knowledge_base_idAWS_REGION=your-aws-region # Defaults to us-east-1AWS_ACCESS_KEY_ID=your-access-key # Required for AWS authenticationAWS_SECRET_ACCESS_KEY=your-secret-key # Required for AWS authentication工具会以 JSON 格式返回结果:
{ "results": [ { "content": "Retrieved text content", "content_type": "text", "source_type": "S3", "source_uri": "s3://bucket/document.pdf", "score": 0.95, "metadata": { "additional": "metadata" } } ], "nextToken": "pagination-token", "guardrailAction": "NONE"}自定义检索配置
Section titled “自定义检索配置”kb_tool = BedrockKBRetrieverTool( knowledge_base_id="your-kb-id", retrieval_configuration={ "vectorSearchConfiguration": { "numberOfResults": 10, "overrideSearchType": "HYBRID" } })
policy_expert = Agent( role='Policy Expert', goal='Analyze company policies in detail', backstory='I am an expert in corporate policy analysis with deep knowledge of regulatory requirements.', tools=[kb_tool])支持的数据源
Section titled “支持的数据源”- Amazon S3
- Confluence
- Salesforce
- SharePoint
- Web pages
- Custom document locations
- Amazon Kendra
- SQL databases
企业知识集成
Section titled “企业知识集成”- 让 CrewAI agents 可以访问组织的专有知识,而不暴露敏感数据
- 让 agents 基于公司的具体政策、流程和文档做决策
- 创建能够基于内部文档回答问题、同时保持数据安全的 agents
专业领域知识
Section titled “专业领域知识”- 将 CrewAI agents 连接到法律、医疗、技术等领域知识库,而无需重新训练模型
- 利用已经在 AWS 环境中维护好的现有知识仓库
- 将 CrewAI 的推理能力与知识库中的领域信息结合起来
数据驱动决策
Section titled “数据驱动决策”- 让 CrewAI agent 的响应基于真实公司数据,而不是通用知识
- 确保 agents 基于你特定的业务上下文和文档给出建议
- 通过从知识库中检索事实信息来减少幻觉
可扩展的信息访问
Section titled “可扩展的信息访问”- 无需把所有组织知识都嵌入模型,也能访问 TB 级别的信息
- 只按需动态查询特定任务所需的相关信息
- 利用 AWS 的可扩展基础设施高效处理大型知识库
- 确保 CrewAI agents 的响应符合公司批准的文档
- 为 agents 使用的信息源创建可审计轨迹
- 控制你的 agents 可以访问哪些信息源