Skip to content

Need a Knowledge Base Retrieval Tool to Provide Supplemental Grounding #44

@rbpotter-aws

Description

@rbpotter-aws

Knowledge Base Retrieval Tool

Summary

A new tool that lets agents retrieve grounding context from a curated knowledge base of semantic terms, taxonomies, and domain definitions. Agents invoke it at query time to pull authoritative chunks, improving terminology consistency and factual accuracy.

No foundation analyzer code — this is purely retrieval.


Components

CDK Stack

Defines the full deployment unit. Creates the Lambda function, wires IAM permissions for Bedrock (embeddings) and OpenSearch Serverless (vector search), and registers the tool with the AgentCore Gateway. Single stack, single cdk deploy.

Lambda Function

Entry point for tool invocations. Receives a query from the gateway, calls the embedder, queries the vector index, filters by score threshold, and returns ranked chunks with metadata. ARM64, Node 20, ~512MB memory, 15s timeout.

Config

Centralizes tunable defaults: tool name/description, embedding model ID (amazon.titan-embed-text-v2:0), index name, top-k (default 5), score threshold (default 0.55), Lambda sizing. All overridable via stack props.

Embedder

Thin client around Bedrock InvokeModel. Takes a query string, returns a normalized vector. Uses Titan Embed Text v2 at 256dimensions.

Retriever

Handles OpenSearch Serverless kNN queries with SigV4-signed requests. Supports optional metadata filters (e.g. { "domain": "finance", "taxonomy": "GL" }). Returns content, score, metadata, and source reference per hit.

Gateway Registration

Registers knowledge_base_retrieve as a tool in the AgentCore Gateway with its input schema and Lambda ARN. Agents see the tool name, description, and schema — standard tool-use contract.


Tool Schema (what agents see)

Parameter Type Required Description
query string yes Natural-language query to search the KB with
top_k number no Override number of results (default 5)
filter object no Metadata key-value filter (e.g. domain, taxonomy)

Response Shape

Each invocation returns a list of results, each containing:

  • content — the retrieved text chunk
  • score — similarity score
  • metadata — domain, taxonomy, source doc, chunk ID, etc.
  • source — reference back to the originating document

Infrastructure Dependencies

  • OpenSearch Serverless collection (vector index, pre-existing)
  • Bedrock access for Titan Embed Text v2
  • AgentCore Gateway (pre-existing, receives tool registration)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions