Skip to content

Knowledge: connect a Bedrock knowledge base in place, searched live in your AWS account - #526

Merged
nambok merged 2 commits into
mainfrom
knowledge-connect-bedrock
Nov 9, 2026
Merged

nambok merged 2 commits into
mainfrom
knowledge-connect-bedrock

Conversation

@nambok

@nambok nambok commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Phase 1 of knowledge base import and connect: an existing Amazon Bedrock knowledge base can be connected in place. It is searched live with bedrock-agent-runtime Retrieve in the team's own AWS account whenever Chat or an agent needs it, and nothing is copied (no documents, passages or vectors). Every existing knowledge base is unchanged: it reads as Local and behaves exactly as before.

Because every consumer (planner, coder, reviewer, plan chat, plugins, brain chat and its citation registry) goes through knowledge::search::search(), a connected base works everywhere at once.

Changes

Search (services/common/src/knowledge)

  • Base.backend: Local (the default, so every stored record reads as before and is saved without the new field) or Remote { provider: BedrockKb, target: <KB ARN>, region (from the ARN), access, hybrid }. access is Install (a self-hosted install's own role) or Account { account } (the team's CoderHelmLogReader role in that account). The team's private ID is never stored on the base; it is read from Coderhelm's own record of the account at search time.
  • A Retriever trait beside Store and Embedder, taking team_id so isolation stays in the signature.
  • search() splits the requested bases by backend. Local bases run as before. Every connected base is asked at once (in parallel with the local embed and index loads), and each answer joins the reciprocal rank fusion as one more ranked list. fuse() now takes any number of lists. The three-per-file cap keys on (base, document id). The Titan embedding runs only when a local file will be scored, so a search of only connected bases never embeds. A connected base that fails is reported in Found::unreached and the others still answer; the search fails only when nothing could be searched, and it says why.
  • remote.rs: ARN parsing, the Bedrock retriever (HYBRID on stores that support it, plain vector search where the store refuses it, found by the test search; no reranking), hits mapped from Retrieve results (content text, document id from metadata or the source address, title or S3 key as the place, a metadata date as as_of, the original page or the S3 console object as the link), and SourceKind::BedrockKb for citations.
  • Failures in plain words (refusal): AccessDenied becomes "The role in your account does not allow Retrieve on this knowledge base."; a permissions boundary refusal says the install's access stack hasn't been applied yet (the same sentence and fix as the Airflow read); a resource policy, an SCP, an unknown ARN, throttling, a failing vector store and an unreachable endpoint (with the VPC endpoint hint) each get their own sentence and fix. Account numbers and ARNs are stripped from AWS's text.

Gateway

  • POST /api/knowledge takes connect: { provider: "bedrock_kb", target }. One test Retrieve runs before anything is saved. When the team's role only lacks the permission, the 400 carries grant: the one-click CoderHelmLogReader update for that account, naming every knowledge base the team connected there.
  • GET /api/knowledge/bedrock: on a self-hosted install, the knowledge bases in its own account and region (bedrock:ListKnowledgeBases); everywhere, the team's connected AWS accounts and the ARNs already connected.
  • POST /api/knowledge/:kb_id/check: one test search now, same answers.
  • Uploads and synced sources are refused on a connected base. The base JSON carries backend.
  • Brain chat and the worker's search_knowledge tool use the Bedrock retriever; an unreached base is told to the model so it doesn't claim the base holds nothing.
  • The AWS account view's update link carries the team's connected knowledge base ARNs, so a later release update keeps the role able to search them.

Access

  • Hosted: the existing ExternalId assumed-role path (live/aws.rs). ReadKnowledgeBases (bedrock:Retrieve, bedrock:GetDocumentContent) is in both coderhelm-log-reader.yaml and coderhelm-log-reader-update.yaml, on a new KnowledgeBases parameter (comma-separated ARNs, or all for every knowledge base in the account, which also adds bedrock:ListKnowledgeBases). Empty, the default, grants nothing. No Bedrock resource policy is used: one naming Coderhelm's shared role would let any team that learned an ARN search it.
  • log_reader::ABILITIES gains a knowledge ability marked chosen: it exists only for what a team names, so the role's live permission check never counts it missing. Update stacks for a set of knowledge bases are named CoderHelmLogReaderUpdate-<id>-kb<hash>, so they never collide with the release's own.
  • Self-host: grantOwnAccountRead builds the install role's policy from the same update template, with KnowledgeBases = all (the install's own account only). CfnInclude keeps Fn::If, so own-account-read.ts decides the template's two conditions itself and fails the build on any condition it doesn't know.

The permissions boundary, and why it changes only in the access stack

  • bedrock:Retrieve is added to BOUNDARY_SERVICES in infra/lib/access.ts. That is today's boundary, which since Self-host updates never wait on the deploy role or its boundary #519 reaches an install only through the admin-applied access stack (access.json): the parent keeps access-pinned.json byte for byte, so no update ever waits on an AWS admin or changes a boundary. GetDocumentContent and ListKnowledgeBases were already covered by bedrock:Get* and bedrock:List*.
  • native-access.test.ts flagged the change, as designed. ACCESS_DOCS.boundary is set to the new sha256, and a new test proves the pinned boundary still refuses Retrieve while today's (in access.json) allows it.
  • Until an admin applies the access stack, connecting a knowledge base in the install's own account says so plainly ("This install's permission limit doesn't allow searching Bedrock knowledge bases yet..." with the Settings, System, Version, Permissions fix), detected from AWS's own "permissions boundary" refusal, like the Airflow read. Nothing else waits on it, and bases in other accounts work without it.
  • This should be batched with any other access-stack change in the release notes, per the comment on ACCESS_DOCS.

Docs: docs/self-host/knowledge-sources.md gets a section on connecting in place, who searches it, the one admin step, private networks and who sees what.

Verification

  • cargo fmt --check, cargo clippy -p common -p gateway -p worker --all-targets -- -D warnings: clean.
  • cargo test -p common -p gateway -p worker: 1582, 765 and 1408 passed. New unit tests use a fake Retriever (no AWS calls): a remote list fused with local ones by rank only, Bedrock's order kept, the per-document cap per base, no embedding when only connected bases are searched (one when a local file is added), team isolation (another team's base id never reaches the retriever; the same id is asked as the asking team), an AccessDenied translated into plain words and the search failing with the base's name when nothing else could answer, ARN parsing, every refusal kind, access selection, the hit mapping, the update link and stack name, and the base JSON and refusals in the gateway.
  • infra: npm test 155 passed; cfn-lint infra/cfn/*.yaml clean.
  • Not run against AWS (no account was touched). Two things to do before merging:
    • infra/test/fixtures/native-sim.json: regenerated with infra/scripts/deploy-role-sim.py --native (AWS's IAM policy simulator, read-only calls). Its boundary allows bedrock:Retrieve; the helper policy and one release asset row also caught up with the current build. 3204 (action, resource) pairs: 3140 allowed, 16 implicit deny, 48 explicit deny; 57 runtime rows.
    • Run one live Retrieve against a test knowledge base, hosted and self-hosted. documentId is not a field of this SDK's KnowledgeBaseRetrievalResult (aws-sdk-bedrockagentruntime 1.125), so the document id comes from the metadata (x-amz-bedrock-kb-document-id, else the source URI).

…n the team's AWS account

A base can now be connected in place instead of copied: an Amazon Bedrock
knowledge base, searched with bedrock-agent-runtime Retrieve each time it is
needed. Nothing is copied: no documents, passages or vectors.

- Base.backend: Local (every existing record, unchanged) or Remote with the
  provider, the knowledge base's ARN, the region from the ARN, and how it is
  reached (the install's own role, or the team's CoderHelmLogReader role in
  that account with the team's private ID).
- A Retriever trait beside Store and Embedder, taking the team. search()
  splits bases by backend, asks every connected base at once, and fuses each
  one's ranked list with the local vector and keyword lists. The per-file
  cap uses the document id; the question is embedded only when a local file
  is searched. A base that doesn't answer is named; the others still answer.
- The Bedrock retriever: HYBRID search where the store supports it (found by
  the test search), no reranking; text, document id, title or S3 key, a
  metadata date and the original link become the hit; SourceKind::BedrockKb.
- Connecting runs one test search first; failures come back in plain words
  (the role does not allow Retrieve, the install's boundary, a resource
  policy, an SCP, no such knowledge base, an unreachable endpoint), with the
  one-click CoderHelmLogReader update when the role only lacks the grant.
- ReadKnowledgeBases in both log reader templates, on a KnowledgeBases
  parameter (ARNs, or all); the install's own role gets every knowledge base
  in its own account through the same update template.
- The boundary gains bedrock:Retrieve in today's boundary only: it reaches an
  install through the admin-applied access stack (access.json), never through
  an update; the pinned parent boundary is unchanged.
- Docs: self-host knowledge sources.
The fixture now comes from AWS's IAM policy simulator rather than a hand
edit: the boundary allows bedrock:Retrieve, and the helper policy and
release asset rows match the current build.
@nambok
nambok force-pushed the knowledge-connect-bedrock branch from 3cdb081 to ca0d813 Compare November 9, 2026 01:51
@nambok
nambok merged commit bb81e2c into main Nov 9, 2026
10 checks passed
@nambok
nambok deleted the knowledge-connect-bedrock branch November 9, 2026 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant