Skip to content

Conversation

@sebsto
Copy link
Collaborator

@sebsto sebsto commented Oct 23, 2025

Add Amazon Bedrock Knowledge Base Retrieval Support

This PR adds support for Amazon Bedrock Agent Runtime's knowledge base retrieval functionality, enabling RAG (Retrieval-Augmented Generation) applications.

Key Changes:

  • Added BedrockAgentRuntimeProtocol and client integration following existing patterns
  • Added retrieve() function to BedrockService for querying knowledge bases
  • Created RetrieveResult wrapper with convenience methods (bestMatch(), toJSON())
  • Added comprehensive documentation and example application
  • Updated Package.swift with AWSBedrockAgentRuntime dependency

Usage:

let result = try await bedrock.retrieve(
    knowledgeBaseId: "your-kb-id", 
    retrievalQuery: "your query"
)
let bestMatch = result.bestMatch()
let jsonContext = try result.toJSON() // For LLM context

@sebsto sebsto self-assigned this Oct 23, 2025
@sebsto sebsto added the enhancement New feature or request label Oct 23, 2025
@sebsto sebsto requested a review from Copilot October 23, 2025 18:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for Amazon Bedrock Agent Runtime's knowledge base retrieval functionality, enabling Retrieval-Augmented Generation (RAG) applications in the Swift Bedrock Library.

Key Changes:

  • Added BedrockAgentRuntimeProtocol and client integration following the existing pattern for other Bedrock clients
  • Implemented retrieve() function in BedrockService for querying knowledge bases with configurable result counts
  • Created RetrieveResult wrapper with convenience methods for accessing results and exporting to JSON

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Sources/BedrockService/BedrockService.swift Integrated BedrockAgentRuntimeClient into BedrockService initialization
Sources/BedrockService/BedrockService+AgentRuntime.swift Added client factory and retrieve() function for knowledge base queries
Sources/BedrockService/RetrieveResult.swift Created result wrapper with bestMatch() and toJSON() convenience methods
Sources/BedrockService/Protocols/BedrockAgentRuntimeProtocol.swift Added protocol for BedrockAgentRuntimeClient to enable mocking
Sources/BedrockService/Protocols/BedrockConfigProtocol.swift Extended BedrockConfigProtocol conformance to BedrockAgentRuntimeClient
Sources/BedrockService/Docs.docc/Retrieval.md Added comprehensive documentation with usage examples
Sources/BedrockService/Docs.docc/BedrockService.md Added Retrieval documentation reference
Package.swift Added AWSBedrockAgentRuntime dependency
Examples/retrieve/Sources/Retrieve.swift Created example application demonstrating knowledge base retrieval
Examples/retrieve/Package.swift Added package manifest for retrieve example
Examples/retrieve/.gitignore Added gitignore for example project

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sebsto sebsto merged commit 0a88772 into main Oct 23, 2025
23 checks passed
@sebsto sebsto deleted the sebsto/agentruntime branch October 23, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant