@mixedbread/sdk 0.1.0-alpha.9 → 0.1.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +383 -0
  2. package/README.md +4 -4
  3. package/_shims/index.d.ts +2 -0
  4. package/_shims/index.js +5 -1
  5. package/_shims/index.mjs +5 -1
  6. package/core.d.ts +11 -0
  7. package/core.d.ts.map +1 -1
  8. package/core.js +5 -2
  9. package/core.js.map +1 -1
  10. package/core.mjs +6 -3
  11. package/core.mjs.map +1 -1
  12. package/index.d.mts +28 -7
  13. package/index.d.ts +28 -7
  14. package/index.d.ts.map +1 -1
  15. package/index.js +32 -8
  16. package/index.js.map +1 -1
  17. package/index.mjs +32 -8
  18. package/index.mjs.map +1 -1
  19. package/package.json +8 -29
  20. package/resources/embeddings.d.ts +45 -0
  21. package/resources/embeddings.d.ts.map +1 -0
  22. package/resources/embeddings.js +20 -0
  23. package/resources/embeddings.js.map +1 -0
  24. package/resources/embeddings.mjs +16 -0
  25. package/resources/embeddings.mjs.map +1 -0
  26. package/resources/extractions/content.d.ts +2 -2
  27. package/resources/extractions/content.d.ts.map +1 -1
  28. package/resources/extractions/jobs.d.ts +3 -3
  29. package/resources/extractions/jobs.d.ts.map +1 -1
  30. package/resources/extractions/schema.d.ts +5 -5
  31. package/resources/extractions/schema.d.ts.map +1 -1
  32. package/resources/extractions.d.ts +2 -0
  33. package/resources/extractions.d.ts.map +1 -0
  34. package/resources/extractions.js +19 -0
  35. package/resources/extractions.js.map +1 -0
  36. package/resources/extractions.mjs +3 -0
  37. package/resources/extractions.mjs.map +1 -0
  38. package/resources/index.d.ts +2 -1
  39. package/resources/index.d.ts.map +1 -1
  40. package/resources/index.js +3 -1
  41. package/resources/index.js.map +1 -1
  42. package/resources/index.mjs +1 -0
  43. package/resources/index.mjs.map +1 -1
  44. package/resources/parsing/jobs.d.ts +8 -0
  45. package/resources/parsing/jobs.d.ts.map +1 -1
  46. package/resources/parsing/jobs.js.map +1 -1
  47. package/resources/parsing/jobs.mjs.map +1 -1
  48. package/resources/parsing.d.ts +2 -0
  49. package/resources/parsing.d.ts.map +1 -0
  50. package/resources/parsing.js +19 -0
  51. package/resources/parsing.js.map +1 -0
  52. package/resources/parsing.mjs +3 -0
  53. package/resources/parsing.mjs.map +1 -0
  54. package/resources/shared.d.ts +14 -0
  55. package/resources/shared.d.ts.map +1 -1
  56. package/resources/top-level.d.ts +174 -1
  57. package/resources/top-level.d.ts.map +1 -1
  58. package/resources/vector-stores/files.d.ts +12 -0
  59. package/resources/vector-stores/files.d.ts.map +1 -1
  60. package/resources/vector-stores/files.js.map +1 -1
  61. package/resources/vector-stores/files.mjs.map +1 -1
  62. package/resources/vector-stores/vector-stores.d.ts +4 -0
  63. package/resources/vector-stores/vector-stores.d.ts.map +1 -1
  64. package/resources/vector-stores/vector-stores.js.map +1 -1
  65. package/resources/vector-stores/vector-stores.mjs.map +1 -1
  66. package/resources/vector-stores.d.ts +2 -0
  67. package/resources/vector-stores.d.ts.map +1 -0
  68. package/resources/vector-stores.js +19 -0
  69. package/resources/vector-stores.js.map +1 -0
  70. package/resources/vector-stores.mjs +3 -0
  71. package/resources/vector-stores.mjs.map +1 -0
  72. package/resources.d.ts +2 -0
  73. package/resources.d.ts.map +1 -0
  74. package/resources.js +18 -0
  75. package/resources.js.map +1 -0
  76. package/resources.mjs +2 -0
  77. package/resources.mjs.map +1 -0
  78. package/src/_shims/index.d.ts +2 -0
  79. package/src/_shims/index.js +5 -1
  80. package/src/_shims/index.mjs +5 -1
  81. package/src/core.ts +23 -4
  82. package/src/index.ts +72 -21
  83. package/src/resources/embeddings.ts +67 -0
  84. package/src/resources/extractions/content.ts +2 -2
  85. package/src/resources/extractions/jobs.ts +3 -3
  86. package/src/resources/extractions/schema.ts +5 -5
  87. package/src/resources/extractions.ts +3 -0
  88. package/src/resources/index.ts +10 -1
  89. package/src/resources/parsing/jobs.ts +10 -0
  90. package/src/resources/parsing.ts +3 -0
  91. package/src/resources/shared.ts +17 -0
  92. package/src/resources/top-level.ts +260 -1
  93. package/src/resources/vector-stores/files.ts +15 -0
  94. package/src/resources/vector-stores/vector-stores.ts +5 -0
  95. package/src/resources/vector-stores.ts +3 -0
  96. package/src/resources.ts +1 -0
  97. package/src/version.ts +1 -1
  98. package/version.d.ts +1 -1
  99. package/version.d.ts.map +1 -1
  100. package/version.js +1 -1
  101. package/version.js.map +1 -1
  102. package/version.mjs +1 -1
  103. package/version.mjs.map +1 -1
package/src/core.ts CHANGED
@@ -16,7 +16,12 @@ import {
16
16
  type RequestInit,
17
17
  type Response,
18
18
  type HeadersInit,
19
+ init,
19
20
  } from './_shims/index';
21
+
22
+ // try running side effects outside of _shims/index to workaround https://github.com/vercel/next.js/issues/76881
23
+ init();
24
+
20
25
  export { type Response };
21
26
  import { BlobLike, isBlobLike, isMultipartBody } from './uploads';
22
27
  export {
@@ -28,6 +33,20 @@ export {
28
33
 
29
34
  export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
30
35
 
36
+ /**
37
+ * An alias to the builtin `Array` type so we can
38
+ * easily alias it in import statements if there are name clashes.
39
+ */
40
+ type _Array<T> = Array<T>;
41
+
42
+ /**
43
+ * An alias to the builtin `Record` type so we can
44
+ * easily alias it in import statements if there are name clashes.
45
+ */
46
+ type _Record<K extends keyof any, T> = Record<K, T>;
47
+
48
+ export type { _Array as Array, _Record as Record };
49
+
31
50
  type PromiseOrValue<T> = T | Promise<T>;
32
51
 
33
52
  type APIResponseProps = {
@@ -48,8 +67,8 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
48
67
  }
49
68
 
50
69
  const contentType = response.headers.get('content-type');
51
- const isJSON =
52
- contentType?.includes('application/json') || contentType?.includes('application/vnd.api+json');
70
+ const mediaType = contentType?.split(';')[0]?.trim();
71
+ const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
53
72
  if (isJSON) {
54
73
  const json = await response.json();
55
74
 
@@ -366,7 +385,7 @@ export abstract class APIClient {
366
385
  getHeader(headers, 'x-stainless-timeout') === undefined &&
367
386
  options.timeout
368
387
  ) {
369
- reqHeaders['x-stainless-timeout'] = String(options.timeout);
388
+ reqHeaders['x-stainless-timeout'] = String(Math.trunc(options.timeout / 1000));
370
389
  }
371
390
 
372
391
  this.validateHeaders(reqHeaders, headers);
@@ -395,7 +414,7 @@ export abstract class APIClient {
395
414
  !headers ? {}
396
415
  : Symbol.iterator in headers ?
397
416
  Object.fromEntries(Array.from(headers as Iterable<string[]>).map((header) => [...header]))
398
- : { ...headers }
417
+ : { ...(headers as any as Record<string, string>) }
399
418
  );
400
419
  }
401
420
 
package/src/index.ts CHANGED
@@ -8,7 +8,16 @@ import { type LimitOffsetParams, LimitOffsetResponse } from './pagination';
8
8
  import * as Uploads from './uploads';
9
9
  import * as API from './resources/index';
10
10
  import * as TopLevelAPI from './resources/top-level';
11
- import { InfoResponse } from './resources/top-level';
11
+ import {
12
+ EmbedParams,
13
+ Embedding,
14
+ EmbeddingCreateResponse,
15
+ InfoResponse,
16
+ MultiEncodingEmbedding,
17
+ RerankParams,
18
+ RerankResponse,
19
+ } from './resources/top-level';
20
+ import { EmbeddingCreateParams, Embeddings } from './resources/embeddings';
12
21
  import {
13
22
  FileCreateParams,
14
23
  FileDeleteResponse,
@@ -40,7 +49,7 @@ import {
40
49
  } from './resources/vector-stores/vector-stores';
41
50
 
42
51
  const environments = {
43
- production: 'https://api.mixedbread.ai',
52
+ production: 'https://api.mixedbread.com',
44
53
  local: 'http://127.0.0.1:8000',
45
54
  };
46
55
  type Environment = keyof typeof environments;
@@ -55,7 +64,7 @@ export interface ClientOptions {
55
64
  * Specifies the environment to use for the API.
56
65
  *
57
66
  * Each environment maps to a different base URL:
58
- * - `production` corresponds to `https://api.mixedbread.ai`
67
+ * - `production` corresponds to `https://api.mixedbread.com`
59
68
  * - `local` corresponds to `http://127.0.0.1:8000`
60
69
  */
61
70
  environment?: Environment | undefined;
@@ -128,9 +137,9 @@ export class Mixedbread extends Core.APIClient {
128
137
  /**
129
138
  * API Client for interfacing with the Mixedbread API.
130
139
  *
131
- * @param {string | undefined} [opts.apiKey=process.env['MXBAI_API_KEY'] ?? undefined]
140
+ * @param {string | undefined} [opts.apiKey=process.env['MIXEDBREAD_API_KEY'] ?? undefined]
132
141
  * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
133
- * @param {string} [opts.baseURL=process.env['MIXEDBREAD_BASE_URL'] ?? https://api.mixedbread.ai] - Override the default base URL for the API.
142
+ * @param {string} [opts.baseURL=process.env['MIXEDBREAD_BASE_URL'] ?? https://api.mixedbread.com] - Override the default base URL for the API.
134
143
  * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
135
144
  * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
136
145
  * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
@@ -140,12 +149,12 @@ export class Mixedbread extends Core.APIClient {
140
149
  */
141
150
  constructor({
142
151
  baseURL = Core.readEnv('MIXEDBREAD_BASE_URL'),
143
- apiKey = Core.readEnv('MXBAI_API_KEY'),
152
+ apiKey = Core.readEnv('MIXEDBREAD_API_KEY'),
144
153
  ...opts
145
154
  }: ClientOptions = {}) {
146
155
  if (apiKey === undefined) {
147
156
  throw new Errors.MixedbreadError(
148
- "The MXBAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the Mixedbread client with an apiKey option, like new Mixedbread({ apiKey: 'My API Key' }).",
157
+ "The MIXEDBREAD_API_KEY environment variable is missing or empty; either provide it, or instantiate the Mixedbread client with an apiKey option, like new Mixedbread({ apiKey: 'My API Key' }).",
149
158
  );
150
159
  }
151
160
 
@@ -175,10 +184,26 @@ export class Mixedbread extends Core.APIClient {
175
184
  this.apiKey = apiKey;
176
185
  }
177
186
 
187
+ vectorStores: API.VectorStores = new API.VectorStores(this);
178
188
  parsing: API.Parsing = new API.Parsing(this);
179
189
  files: API.Files = new API.Files(this);
180
- vectorStores: API.VectorStores = new API.VectorStores(this);
181
190
  extractions: API.Extractions = new API.Extractions(this);
191
+ embeddings: API.Embeddings = new API.Embeddings(this);
192
+
193
+ /**
194
+ * Create embeddings for text or images using the specified model, encoding format,
195
+ * and normalization.
196
+ *
197
+ * Args: params: The parameters for creating embeddings.
198
+ *
199
+ * Returns: EmbeddingCreateResponse: The response containing the embeddings.
200
+ */
201
+ embed(
202
+ body: TopLevelAPI.EmbedParams,
203
+ options?: Core.RequestOptions,
204
+ ): Core.APIPromise<TopLevelAPI.EmbeddingCreateResponse> {
205
+ return this.post('/v1/embeddings', { body, ...options });
206
+ }
182
207
 
183
208
  /**
184
209
  * Returns service information, including name and version.
@@ -189,6 +214,20 @@ export class Mixedbread extends Core.APIClient {
189
214
  return this.get('/', options);
190
215
  }
191
216
 
217
+ /**
218
+ * Rerank different kind of documents for a given query.
219
+ *
220
+ * Args: params: RerankParams: The parameters for reranking.
221
+ *
222
+ * Returns: RerankResponse: The reranked documents for the input query.
223
+ */
224
+ rerank(
225
+ body: TopLevelAPI.RerankParams,
226
+ options?: Core.RequestOptions,
227
+ ): Core.APIPromise<TopLevelAPI.RerankResponse> {
228
+ return this.post('/v1/reranking', { body, ...options });
229
+ }
230
+
192
231
  protected override defaultQuery(): Core.DefaultQuery | undefined {
193
232
  return this._options.defaultQuery;
194
233
  }
@@ -225,30 +264,27 @@ export class Mixedbread extends Core.APIClient {
225
264
  static fileFromPath = Uploads.fileFromPath;
226
265
  }
227
266
 
267
+ Mixedbread.VectorStores = VectorStores;
268
+ Mixedbread.VectorStoresLimitOffset = VectorStoresLimitOffset;
228
269
  Mixedbread.Parsing = Parsing;
229
270
  Mixedbread.Files = Files;
230
271
  Mixedbread.FileObjectsLimitOffset = FileObjectsLimitOffset;
231
- Mixedbread.VectorStores = VectorStores;
232
- Mixedbread.VectorStoresLimitOffset = VectorStoresLimitOffset;
233
272
  Mixedbread.Extractions = Extractions;
273
+ Mixedbread.Embeddings = Embeddings;
234
274
  export declare namespace Mixedbread {
235
275
  export type RequestOptions = Core.RequestOptions;
236
276
 
237
277
  export import LimitOffset = Pagination.LimitOffset;
238
278
  export { type LimitOffsetParams as LimitOffsetParams, type LimitOffsetResponse as LimitOffsetResponse };
239
279
 
240
- export { type InfoResponse as InfoResponse };
241
-
242
- export { Parsing as Parsing };
243
-
244
280
  export {
245
- Files as Files,
246
- type FileObject as FileObject,
247
- type FileDeleteResponse as FileDeleteResponse,
248
- FileObjectsLimitOffset as FileObjectsLimitOffset,
249
- type FileCreateParams as FileCreateParams,
250
- type FileUpdateParams as FileUpdateParams,
251
- type FileListParams as FileListParams,
281
+ type Embedding as Embedding,
282
+ type EmbeddingCreateResponse as EmbeddingCreateResponse,
283
+ type MultiEncodingEmbedding as MultiEncodingEmbedding,
284
+ type InfoResponse as InfoResponse,
285
+ type RerankResponse as RerankResponse,
286
+ type EmbedParams as EmbedParams,
287
+ type RerankParams as RerankParams,
252
288
  };
253
289
 
254
290
  export {
@@ -270,10 +306,25 @@ export declare namespace Mixedbread {
270
306
  type VectorStoreSearchParams as VectorStoreSearchParams,
271
307
  };
272
308
 
309
+ export { Parsing as Parsing };
310
+
311
+ export {
312
+ Files as Files,
313
+ type FileObject as FileObject,
314
+ type FileDeleteResponse as FileDeleteResponse,
315
+ FileObjectsLimitOffset as FileObjectsLimitOffset,
316
+ type FileCreateParams as FileCreateParams,
317
+ type FileUpdateParams as FileUpdateParams,
318
+ type FileListParams as FileListParams,
319
+ };
320
+
273
321
  export { Extractions as Extractions };
274
322
 
323
+ export { Embeddings as Embeddings, type EmbeddingCreateParams as EmbeddingCreateParams };
324
+
275
325
  export type SearchFilter = API.SearchFilter;
276
326
  export type SearchFilterCondition = API.SearchFilterCondition;
327
+ export type Usage = API.Usage;
277
328
  }
278
329
 
279
330
  export { toFile, fileFromPath } from './uploads';
@@ -0,0 +1,67 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../resource';
4
+ import * as Core from '../core';
5
+ import * as TopLevelAPI from './top-level';
6
+
7
+ export class Embeddings extends APIResource {
8
+ /**
9
+ * Create embeddings for text or images using the specified model, encoding format,
10
+ * and normalization.
11
+ *
12
+ * Args: params: The parameters for creating embeddings.
13
+ *
14
+ * Returns: EmbeddingCreateResponse: The response containing the embeddings.
15
+ */
16
+ create(
17
+ body: EmbeddingCreateParams,
18
+ options?: Core.RequestOptions,
19
+ ): Core.APIPromise<TopLevelAPI.EmbeddingCreateResponse> {
20
+ return this._client.post('/v1/embeddings', { body, ...options });
21
+ }
22
+ }
23
+
24
+ export interface EmbeddingCreateParams {
25
+ /**
26
+ * The model to use for creating embeddings.
27
+ */
28
+ model: string;
29
+
30
+ /**
31
+ * The input to create embeddings for.
32
+ */
33
+ input: Array<string>;
34
+
35
+ /**
36
+ * The number of dimensions to use for the embeddings.
37
+ */
38
+ dimensions?: number | null;
39
+
40
+ /**
41
+ * The prompt to use for the embedding creation.
42
+ */
43
+ prompt?: string | null;
44
+
45
+ /**
46
+ * Whether to normalize the embeddings.
47
+ */
48
+ normalized?: boolean;
49
+
50
+ /**
51
+ * The encoding format(s) of the embeddings. Can be a single format or a list of
52
+ * formats.
53
+ */
54
+ encoding_format?:
55
+ | 'float'
56
+ | 'float16'
57
+ | 'base64'
58
+ | 'binary'
59
+ | 'ubinary'
60
+ | 'int8'
61
+ | 'uint8'
62
+ | Array<'float' | 'float16' | 'base64' | 'binary' | 'ubinary' | 'int8' | 'uint8'>;
63
+ }
64
+
65
+ export declare namespace Embeddings {
66
+ export { type EmbeddingCreateParams as EmbeddingCreateParams };
67
+ }
@@ -20,7 +20,7 @@ export class Content extends APIResource {
20
20
  * The result of an extraction job.
21
21
  */
22
22
  export interface ExtractionResult {
23
- data: unknown;
23
+ data: Record<string, unknown>;
24
24
 
25
25
  warnings: Array<string>;
26
26
  }
@@ -34,7 +34,7 @@ export interface ContentCreateParams {
34
34
  /**
35
35
  * The JSON schema to use for extraction
36
36
  */
37
- json_schema: unknown;
37
+ json_schema: Record<string, unknown>;
38
38
  }
39
39
 
40
40
  export declare namespace Content {
@@ -80,12 +80,12 @@ export interface ExtractionJob {
80
80
  /**
81
81
  * Error information if failed
82
82
  */
83
- error: unknown | null;
83
+ error: Record<string, unknown> | null;
84
84
 
85
85
  /**
86
86
  * The JSON schema used for extraction
87
87
  */
88
- json_schema: unknown;
88
+ json_schema: Record<string, unknown>;
89
89
  }
90
90
 
91
91
  export interface JobCreateParams {
@@ -97,7 +97,7 @@ export interface JobCreateParams {
97
97
  /**
98
98
  * The JSON schema to use for extraction
99
99
  */
100
- json_schema: unknown;
100
+ json_schema: Record<string, unknown>;
101
101
  }
102
102
 
103
103
  export declare namespace Jobs {
@@ -45,7 +45,7 @@ export interface CreatedJsonSchema {
45
45
  /**
46
46
  * The created JSON schema
47
47
  */
48
- json_schema: unknown;
48
+ json_schema: Record<string, unknown>;
49
49
  }
50
50
 
51
51
  /**
@@ -55,7 +55,7 @@ export interface EnhancedJsonSchema {
55
55
  /**
56
56
  * The enhanced JSON schema
57
57
  */
58
- json_schema: unknown;
58
+ json_schema: Record<string, unknown>;
59
59
  }
60
60
 
61
61
  /**
@@ -75,7 +75,7 @@ export interface ValidatedJsonSchema {
75
75
  /**
76
76
  * The validated JSON schema
77
77
  */
78
- json_schema: unknown;
78
+ json_schema: Record<string, unknown>;
79
79
  }
80
80
 
81
81
  export interface SchemaCreateParams {
@@ -89,14 +89,14 @@ export interface SchemaEnhanceParams {
89
89
  /**
90
90
  * The JSON schema to enhance
91
91
  */
92
- json_schema: unknown;
92
+ json_schema: Record<string, unknown>;
93
93
  }
94
94
 
95
95
  export interface SchemaValidateParams {
96
96
  /**
97
97
  * The JSON schema to validate
98
98
  */
99
- json_schema: unknown;
99
+ json_schema: Record<string, unknown>;
100
100
  }
101
101
 
102
102
  export declare namespace Schema {
@@ -0,0 +1,3 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export * from './extractions/index';
@@ -1,6 +1,7 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  export * from './shared';
4
+ export { Embeddings, type EmbeddingCreateParams } from './embeddings';
4
5
  export { Extractions } from './extractions/extractions';
5
6
  export {
6
7
  FileObjectsLimitOffset,
@@ -30,4 +31,12 @@ export {
30
31
  type VectorStoreQuestionAnsweringParams,
31
32
  type VectorStoreSearchParams,
32
33
  } from './vector-stores/vector-stores';
33
- export { type InfoResponse } from './top-level';
34
+ export {
35
+ type Embedding,
36
+ type EmbeddingCreateResponse,
37
+ type MultiEncodingEmbedding,
38
+ type InfoResponse,
39
+ type RerankResponse,
40
+ type EmbedParams,
41
+ type RerankParams,
42
+ } from './top-level';
@@ -178,6 +178,11 @@ export interface ParsingJob {
178
178
  */
179
179
  id: string;
180
180
 
181
+ /**
182
+ * The ID of the file to parse
183
+ */
184
+ file_id: string;
185
+
181
186
  /**
182
187
  * The status of the job
183
188
  */
@@ -342,6 +347,11 @@ export interface JobListResponse {
342
347
  */
343
348
  id: string;
344
349
 
350
+ /**
351
+ * The ID of the file to parse
352
+ */
353
+ file_id: string;
354
+
345
355
  /**
346
356
  * The status of the job
347
357
  */
@@ -0,0 +1,3 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export * from './parsing/index';
@@ -39,3 +39,20 @@ export interface SearchFilterCondition {
39
39
  */
40
40
  operator: 'eq' | 'not_eq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'not_in' | 'like' | 'not_like';
41
41
  }
42
+
43
+ export interface Usage {
44
+ /**
45
+ * The number of tokens used for the prompt
46
+ */
47
+ prompt_tokens: number;
48
+
49
+ /**
50
+ * The total number of tokens used
51
+ */
52
+ total_tokens: number;
53
+
54
+ /**
55
+ * The number of tokens used for the completion
56
+ */
57
+ completion_tokens?: number | null;
58
+ }