You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33Lines changed: 33 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -857,6 +857,39 @@ let textCompletion = try await bedrock.completeText(
857
857
858
858
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.
859
859
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 =tryawait 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 =tryawait 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.
0 commit comments