@tanstack/ai-bedrock 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Provider options for the Bedrock embedding models.
3
+ *
4
+ * `dimensions` is deliberately absent from every options shape: it's a
5
+ * first-class top-level option on `embed()`. The adapter maps it onto each
6
+ * model's native field (Titan Text `dimensions`, Titan Multimodal
7
+ * `embeddingConfig.outputEmbeddingLength`) and rejects it for the Cohere
8
+ * models, whose output size is fixed.
9
+ */
10
+
11
+ /** Options for `amazon.titan-embed-text-v2:0`. */
12
+ export interface BedrockTitanTextEmbeddingProviderOptions {
13
+ /**
14
+ * Normalize the output embedding to unit length. Titan's service-side
15
+ * default is `true`; leave unset to use it.
16
+ */
17
+ normalize?: boolean
18
+ }
19
+
20
+ /**
21
+ * Options for `amazon.titan-embed-image-v1` (Titan Multimodal Embeddings).
22
+ * The model has no per-request options beyond the top-level `dimensions`
23
+ * (mapped onto `embeddingConfig.outputEmbeddingLength`).
24
+ */
25
+ export type BedrockTitanImageEmbeddingProviderOptions = Record<string, never>
26
+
27
+ /**
28
+ * Cohere embed input types. Cohere REQUIRES the caller to say what the
29
+ * embeddings are for; there is no service-side default.
30
+ */
31
+ export type BedrockCohereEmbeddingInputType =
32
+ | 'search_document'
33
+ | 'search_query'
34
+ | 'classification'
35
+ | 'clustering'
36
+
37
+ /** Options for `cohere.embed-english-v3` / `cohere.embed-multilingual-v3`. */
38
+ export interface BedrockCohereEmbeddingProviderOptions {
39
+ /**
40
+ * What the embeddings will be used for (required by the Cohere API; sent
41
+ * as `input_type`). Use `search_document` when indexing, `search_query`
42
+ * when querying, `classification` / `clustering` for those downstream
43
+ * tasks. Because this field is required, `modelOptions` is required at the
44
+ * `embed()` call site for the Cohere models.
45
+ */
46
+ inputType: BedrockCohereEmbeddingInputType
47
+ /**
48
+ * How to handle inputs longer than the model's maximum token length.
49
+ * `NONE` (the API default) returns an error, `START` / `END` truncate
50
+ * from that side.
51
+ */
52
+ truncate?: 'NONE' | 'START' | 'END'
53
+ }
54
+
55
+ /**
56
+ * Broad union used as the adapter's base `TProviderOptions` fallback when
57
+ * the model isn't statically known. Per-model narrowing happens via
58
+ * `BedrockEmbeddingModelProviderOptionsByName`.
59
+ */
60
+ export type BedrockEmbeddingProviderOptions =
61
+ | BedrockTitanTextEmbeddingProviderOptions
62
+ | BedrockTitanImageEmbeddingProviderOptions
63
+ | BedrockCohereEmbeddingProviderOptions
package/src/index.ts CHANGED
@@ -161,6 +161,19 @@ export {
161
161
  createBedrockConverse,
162
162
  type BedrockConverseConfig,
163
163
  } from './adapters/converse-text'
164
+ export {
165
+ BedrockEmbeddingAdapter,
166
+ bedrockEmbedding,
167
+ createBedrockEmbedding,
168
+ type BedrockEmbeddingConfig,
169
+ } from './adapters/embedding'
170
+ export type {
171
+ BedrockCohereEmbeddingInputType,
172
+ BedrockCohereEmbeddingProviderOptions,
173
+ BedrockEmbeddingProviderOptions,
174
+ BedrockTitanImageEmbeddingProviderOptions,
175
+ BedrockTitanTextEmbeddingProviderOptions,
176
+ } from './embedding/embedding-provider-options'
164
177
  export type { BedrockConverseProviderOptions } from './converse/provider-options'
165
178
  export {
166
179
  resolveBedrockAuth,
@@ -173,6 +186,10 @@ export {
173
186
  BEDROCK_CHAT_MODELS,
174
187
  BEDROCK_RESPONSES_MODELS,
175
188
  BEDROCK_CONVERSE_MODELS,
189
+ BEDROCK_EMBEDDING_MODELS,
190
+ type BedrockEmbeddingModel,
191
+ type BedrockEmbeddingModelProviderOptionsByName,
192
+ type BedrockEmbeddingModelInputModalitiesByName,
176
193
  type BedrockChatModels,
177
194
  type BedrockResponsesModels,
178
195
  type BedrockConverseModels,
package/src/model-meta.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { GENERATED_BEDROCK_MODELS } from './model-catalog.generated.js'
2
2
  import type { BedrockTextProviderOptions } from './text/text-provider-options'
3
3
  import type { BedrockConverseProviderOptions } from './converse/provider-options'
4
+ import type {
5
+ BedrockCohereEmbeddingProviderOptions,
6
+ BedrockEmbeddingProviderOptions,
7
+ BedrockTitanImageEmbeddingProviderOptions,
8
+ BedrockTitanTextEmbeddingProviderOptions,
9
+ } from './embedding/embedding-provider-options'
4
10
 
5
11
  type Entry = (typeof GENERATED_BEDROCK_MODELS)[number]
6
12
 
@@ -67,3 +73,50 @@ export type ResolveInputModalities<TModel extends string> =
67
73
  TModel extends keyof BedrockModelInputModalitiesByName
68
74
  ? BedrockModelInputModalitiesByName[TModel]
69
75
  : readonly ['text']
76
+
77
+ // ============================================================================
78
+ // Embedding models
79
+ // ============================================================================
80
+
81
+ /**
82
+ * Embedding models reachable through Bedrock's `InvokeModel` API. These are
83
+ * not part of the generated Converse catalog (embedding models have no
84
+ * conversational surface), so they're maintained by hand here.
85
+ */
86
+ export const BEDROCK_EMBEDDING_MODELS = [
87
+ 'amazon.titan-embed-text-v2:0',
88
+ 'amazon.titan-embed-image-v1',
89
+ 'cohere.embed-english-v3',
90
+ 'cohere.embed-multilingual-v3',
91
+ ] as const
92
+
93
+ export type BedrockEmbeddingModel = (typeof BEDROCK_EMBEDDING_MODELS)[number]
94
+
95
+ /**
96
+ * Type-only map from embedding model name to its provider options type.
97
+ * The Cohere models make `modelOptions` REQUIRED at the `embed()` call site
98
+ * because `inputType` is a required field.
99
+ */
100
+ export type BedrockEmbeddingModelProviderOptionsByName = {
101
+ 'amazon.titan-embed-text-v2:0': BedrockTitanTextEmbeddingProviderOptions
102
+ 'amazon.titan-embed-image-v1': BedrockTitanImageEmbeddingProviderOptions
103
+ 'cohere.embed-english-v3': BedrockCohereEmbeddingProviderOptions
104
+ 'cohere.embed-multilingual-v3': BedrockCohereEmbeddingProviderOptions
105
+ }
106
+
107
+ /**
108
+ * Per-model input modalities for embedding models. Titan Multimodal accepts
109
+ * text and/or images (including fused text+image items embedded into one
110
+ * vector); the rest are text-only, so image inputs fail at compile time.
111
+ */
112
+ export type BedrockEmbeddingModelInputModalitiesByName = {
113
+ 'amazon.titan-embed-text-v2:0': readonly ['text']
114
+ 'amazon.titan-embed-image-v1': readonly ['text', 'image']
115
+ 'cohere.embed-english-v3': readonly ['text']
116
+ 'cohere.embed-multilingual-v3': readonly ['text']
117
+ }
118
+
119
+ export type ResolveEmbeddingProviderOptions<TModel extends string> =
120
+ TModel extends keyof BedrockEmbeddingModelProviderOptionsByName
121
+ ? BedrockEmbeddingModelProviderOptionsByName[TModel]
122
+ : BedrockEmbeddingProviderOptions