Skip to content

Commit fc4553b

Browse files
committed
add swift docc header
1 parent f43297e commit fc4553b

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

Sources/BedrockService/BedrockService+AgentRuntime.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ extension BedrockService {
3636
)
3737
return BedrockAgentRuntimeClient(config: config)
3838
}
39-
/// Retrieves information from a knowledge base
39+
/// Retrieves information from a knowledge base for RAG applications
40+
///
41+
/// This method queries an Amazon Bedrock knowledge base to retrieve relevant information
42+
/// that can be used for Retrieval-Augmented Generation (RAG) applications.
43+
///
4044
/// - Parameters:
4145
/// - knowledgeBaseId: The unique identifier of the knowledge base to query
4246
/// - retrievalQuery: The query to search for in the knowledge base
4347
/// - numberOfResults: The number of results to return (optional, defaults to 3)
44-
/// - Returns: RetrieveResult containing the retrieved results
48+
/// - Returns: RetrieveResult containing the retrieved results with convenience methods
4549
/// - Throws: BedrockLibraryError or other errors from the underlying service
4650
public func retrieve(
4751
knowledgeBaseId: String,

Sources/BedrockService/Protocols/BedrockAgentRuntimeProtocol.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ import FoundationEssentials
2222
import Foundation
2323
#endif
2424

25-
// Protocol allows writing mocks for unit tests
25+
/// Protocol for Amazon Bedrock Agent Runtime operations
26+
///
27+
/// This protocol allows writing mocks for unit tests and provides a clean interface
28+
/// for knowledge base retrieval operations.
2629
public protocol BedrockAgentRuntimeProtocol: Sendable {
30+
/// Retrieves information from a knowledge base
31+
/// - Parameter input: The retrieve input containing query and configuration
32+
/// - Returns: RetrieveOutput with the retrieved results
33+
/// - Throws: Error if the retrieval operation fails
2734
func retrieve(input: RetrieveInput) async throws -> RetrieveOutput
2835
}
2936

Sources/BedrockService/RetrieveRequest.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@
1515

1616
@preconcurrency import AWSBedrockAgentRuntime
1717

18+
/// A request for retrieving information from a knowledge base
1819
public struct RetrieveRequest: Sendable {
20+
/// The unique identifier of the knowledge base to query
1921
public let knowledgeBaseId: String
22+
/// The query text to search for in the knowledge base
2023
public let retrievalQuery: String
24+
/// The number of results to return
2125
public let numberOfResults: Int
2226

27+
/// Creates a new retrieve request
28+
/// - Parameters:
29+
/// - knowledgeBaseId: The unique identifier of the knowledge base to query
30+
/// - retrievalQuery: The query text to search for in the knowledge base
31+
/// - numberOfResults: The number of results to return (defaults to 3)
2332
public init(
2433
knowledgeBaseId: String,
2534
retrievalQuery: String,

Sources/BedrockService/RetrieveResult.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import FoundationEssentials
2121
import Foundation
2222
#endif
2323

24+
/// Type alias for knowledge base retrieval result
2425
public typealias RAGRetrievalResult = BedrockAgentRuntimeClientTypes.KnowledgeBaseRetrievalResult
2526

2627
internal struct SerializableResult: Codable {
@@ -29,21 +30,31 @@ internal struct SerializableResult: Codable {
2930
let source: String?
3031
}
3132

33+
/// A wrapper around RetrieveOutput providing convenient access to retrieval results
3234
public struct RetrieveResult: Sendable {
35+
/// The underlying AWS SDK RetrieveOutput
3336
public let output: RetrieveOutput
3437

38+
/// Creates a new RetrieveResult from a RetrieveOutput
39+
/// - Parameter output: The AWS SDK RetrieveOutput to wrap
3540
public init(_ output: RetrieveOutput) {
3641
self.output = output
3742
}
3843

44+
/// The retrieval results from the knowledge base query
3945
public var results: [RAGRetrievalResult]? {
4046
output.retrievalResults
4147
}
4248

49+
/// Returns the retrieval result with the highest relevance score
50+
/// - Returns: The best matching result, or nil if no results
4351
public func bestMatch() -> RAGRetrievalResult? {
4452
output.retrievalResults?.max { ($0.score ?? 0) < ($1.score ?? 0) }
4553
}
4654

55+
/// Converts the retrieval results to JSON format for use with language models
56+
/// - Returns: JSON string representation of the results
57+
/// - Throws: Error if JSON encoding fails
4758
public func toJSON() throws -> String {
4859
guard let results = output.retrievalResults else { return "[]" }
4960

0 commit comments

Comments
 (0)