Skip to content

Commit db7e13f

Browse files
committed
add embeddings in the README
1 parent 0cd85b1 commit db7e13f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,39 @@ let textCompletion = try await bedrock.completeText(
857857

858858
Note that the minimum, maximum and default values for each parameter are model specific and defined when the BedrockModel is created. Some parameters might not be supported by certain models.
859859

860+
## Generating embeddings using the InvokeModel API
861+
862+
Choose a BedrockModel that supports embeddings generation - you can verify this using the `hasEmbeddingsModality` function. The `embed` function allows you to convert text into numerical vector representations that capture semantic meaning:
863+
864+
```swift
865+
let model: BedrockModel = .titan_embed_text_v1
866+
867+
let embeddings = try await bedrock.embed(
868+
"Swift is a powerful programming language",
869+
with: model
870+
)
871+
872+
print("Generated embeddings with \(embeddings.count) dimensions")
873+
```
874+
875+
Optionally specify the vector size:
876+
877+
```swift
878+
let embeddings = try await bedrock.embed(
879+
"Swift is a powerful programming language",
880+
with: model,
881+
vectorSize: 512
882+
)
883+
```
884+
885+
Embeddings are returned as an array of Double values (`Embeddings` typealias) that can be used for:
886+
- Semantic similarity comparisons
887+
- Text clustering and classification
888+
- Retrieval-augmented generation (RAG) systems
889+
- Machine learning feature vectors
890+
891+
Note that the available vector sizes and other parameters are model specific and defined when the BedrockModel is created.
892+
860893
## How to add a BedrockModel
861894

862895
### Converse

0 commit comments

Comments
 (0)