Skip to content

Commit 5f4f8a2

Browse files
authored
findEmbeddingProviders support (#62)
* findEmbeddingProviders support (no tests + docs) * fixes tiny bug in vectorize tests * docs for findEmbeddingProviders * tiny bit more documenation * one more test for findEmbeddingProviders
1 parent 514417a commit 5f4f8a2

File tree

9 files changed

+550
-38
lines changed

9 files changed

+550
-38
lines changed

src/data-api/db.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ import { DataAPIDbAdmin } from '@/src/devops/data-api-db-admin';
5858
* Db spawning methods let you pass in the default namespace for the database, which is used for all subsequent db
5959
* operations in that object, but each method lets you override the namespace if necessary in its options.
6060
*
61-
* @example
62-
* ```typescript
61+
* {@link DbAdmin.findEmbeddingProviders}typescript
6362
* const client = new DataAPIClient('AstraCS:...');
6463
*
6564
* // Connect to a database using a direct endpoint

src/data-api/embedding-providers/embedding-headers-provider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ import { EmbeddingAPIKeyHeaderProvider } from '@/src/data-api/embedding-provider
3131
* translated into an {@link EmbeddingAPIKeyHeaderProvider} under the hood.
3232
*
3333
* @example
34-
* ```
34+
* ```typescript
35+
* // Using explicit `EmbeddingHeadersProvider`
3536
* const provider = new AWSEmbeddingHeadersProvider('access-key-id', 'secret-access-key');
36-
* const collection = await db.collection('my_coll', { embeddingApiKey: provider });
37+
* const coll1 = await db.collection('my_coll1', { embeddingApiKey: provider });
38+
*
39+
* // Implicitly converted to `EmbeddingAPIKeyHeaderProvider`
40+
* const coll2 = await db.collection('my_coll2', { embeddingApiKey: 'sk-...' });
3741
* ```
3842
*
3943
* @see EmbeddingAPIKeyHeaderProvider

src/data-api/types/collections/collections-common.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface VectorOptions {
3636
* - Some models require a specific dimension that's already set by default
3737
*
3838
* You can find out more information about each model in the [DataStax docs](https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html),
39-
* or through the `findEmbeddingsProvider` command.
39+
* or through {@link DbAdmin.findEmbeddingProviders}.
4040
*/
4141
dimension?: number,
4242
/**
@@ -46,9 +46,11 @@ export interface VectorOptions {
4646
*/
4747
metric?: 'cosine' | 'euclidean' | 'dot_product',
4848
/**
49-
* NOTE: This feature is under current development.
49+
* The options for defining the embedding service used for vectorize, to automatically transform your
50+
* text into a vector ready for semantic vector searching.
5051
*
51-
* @alpha
52+
* You can find out more information about each provider/model in the [DataStax docs](https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html),
53+
* or through {@link DbAdmin.findEmbeddingProviders}.
5254
*/
5355
service?: VectorizeServiceOptions,
5456
}
@@ -58,7 +60,7 @@ export interface VectorOptions {
5860
* text into a vector ready for semantic vector searching.
5961
*
6062
* You can find out more information about each provider/model in the [DataStax docs](https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html),
61-
* or through the `findEmbeddingsProvider` command.
63+
* or through {@link DbAdmin.findEmbeddingProviders}.
6264
*
6365
* @field provider - The name of the embedding provider which provides the model to use
6466
* @field model - The specific model to use for embedding, or undefined if it's an endpoint-defined model
@@ -72,16 +74,14 @@ export interface VectorizeServiceOptions {
7274
* The name of the embedding provider which provides the model to use.
7375
*
7476
* You can find out more information about each provider in the [DataStax docs](https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html),
75-
* or through the `findEmbeddingsProvider` command.
77+
* or through {@link DbAdmin.findEmbeddingProviders}.
7678
*/
7779
provider: string,
7880
/**
7981
* The name of the embedding model to use.
8082
*
81-
* In some situations, this may be `null`/`undefined` if the model may be arbitrary (such as with `huggingfaceDedicated`).
82-
*
8383
* You can find out more information about each model in the [DataStax docs](https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html),
84-
* or through the `findEmbeddingsProvider` command.
84+
* or through {@link DbAdmin.findEmbeddingProviders}.
8585
*/
8686
modelName: string | nullish,
8787
/**
@@ -101,7 +101,7 @@ export interface VectorizeServiceOptions {
101101
* optional parameters (e.g. `openAi`), and some don't require any at all.
102102
*
103103
* You can find out more information about each provider/model in the [DataStax docs](https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html),
104-
* or through the `findEmbeddingsProvider` command.
104+
* or through {@link DbAdmin.findEmbeddingProviders}.
105105
*/
106106
parameters?: Record<string, unknown>,
107107
}

src/devops/astra-db-admin.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { WithTimeout } from '@/src/common/types';
2121
import { InternalRootClientOpts } from '@/src/client/types';
2222
import { isNullish, StaticTokenProvider, TokenProvider } from '@/src/common';
2323
import { validateAdminOpts } from '@/src/devops/utils';
24+
import { FindEmbeddingProvidersResult } from '@/src/devops/types/db-admin/find-embedding-providers';
2425

2526
/**
2627
* An administrative class for managing Astra databases, including creating, listing, and deleting namespaces.
@@ -122,6 +123,27 @@ export class AstraDbAdmin extends DbAdmin {
122123
return this.#db;
123124
}
124125

126+
/**
127+
* Returns detailed information about the availability and usage of the vectorize embedding providers available on the
128+
* current database (may vary based on cloud provider & region).
129+
*
130+
* @example
131+
* ```typescript
132+
* const { embeddingProviders } = await dbAdmin.findEmbeddingProviders();
133+
*
134+
* // ['text-embedding-3-small', 'text-embedding-3-large', 'text-embedding-ada-002']
135+
* console.log(embeddingProviders['openai'].models.map(m => m.name));
136+
* ```
137+
*
138+
* @param options - The options for the timeout of the operation.
139+
*
140+
* @returns The available embedding providers.
141+
*/
142+
public override async findEmbeddingProviders(options?: WithTimeout): Promise<FindEmbeddingProvidersResult> {
143+
const resp = await this.#db.command({ findEmbeddingProviders: {} }, { namespace: null, maxTimeMS: options?.maxTimeMS });
144+
return resp.status as FindEmbeddingProvidersResult;
145+
}
146+
125147
/**
126148
* Fetches the complete information about the database, such as the database name, IDs, region, status, actions, and
127149
* other metadata.

src/devops/data-api-db-admin.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { DbAdmin } from '@/src/devops/db-admin';
2020
import { WithTimeout } from '@/src/common/types';
2121
import { validateAdminOpts } from '@/src/devops/utils';
2222
import { LocalCreateNamespaceOptions } from '@/src/devops/types/db-admin/local-create-namespace';
23+
import { FindEmbeddingProvidersResult } from '@/src/devops/types/db-admin/find-embedding-providers';
2324

2425
/**
2526
* An administrative class for managing non-Astra databases, including creating, listing, and deleting namespaces.
@@ -92,6 +93,27 @@ export class DataAPIDbAdmin extends DbAdmin {
9293
return this.#db;
9394
}
9495

96+
/**
97+
* Returns detailed information about the availability and usage of the vectorize embedding providers available on the
98+
* current database (may vary based on cloud provider & region).
99+
*
100+
* @example
101+
* ```typescript
102+
* const { embeddingProviders } = await dbAdmin.findEmbeddingProviders();
103+
*
104+
* // ['text-embedding-3-small', 'text-embedding-3-large', 'text-embedding-ada-002']
105+
* console.log(embeddingProviders['openai'].models.map(m => m.name));
106+
* ```
107+
*
108+
* @param options - The options for the timeout of the operation.
109+
*
110+
* @returns The available embedding providers.
111+
*/
112+
public override async findEmbeddingProviders(options?: WithTimeout): Promise<FindEmbeddingProvidersResult> {
113+
const resp = await this.#httpClient.executeCommand({ findEmbeddingProviders: {} }, { namespace: null, maxTimeMS: options?.maxTimeMS });
114+
return resp.status as FindEmbeddingProvidersResult;
115+
}
116+
95117
/**
96118
* Lists the namespaces in the database.
97119
*

src/devops/db-admin.ts

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

1616
import { AdminBlockingOptions, CreateNamespaceOptions } from '@/src/devops/types';
1717
import { Db } from '@/src/data-api';
18+
import { FindEmbeddingProvidersResult } from '@/src/devops/types/db-admin/find-embedding-providers';
19+
import { WithTimeout } from '@/src/common';
1820

1921
/**
2022
* Represents some DatabaseAdmin class used for managing some specific database.
@@ -45,6 +47,24 @@ export abstract class DbAdmin {
4547
* @returns The underlying `Db` object.
4648
*/
4749
abstract db(): Db;
50+
51+
/**
52+
* Returns detailed information about the availability and usage of the vectorize embedding providers available on the
53+
* current database (may vary based on cloud provider & region).
54+
*
55+
* @example
56+
* ```typescript
57+
* const { embeddingProviders } = await dbAdmin.findEmbeddingProviders();
58+
*
59+
* // ['text-embedding-3-small', 'text-embedding-3-large', 'text-embedding-ada-002']
60+
* console.log(embeddingProviders['openai'].models.map(m => m.name));
61+
* ```
62+
*
63+
* @param options - The options for the timeout of the operation.
64+
*
65+
* @returns The available embedding providers.
66+
*/
67+
abstract findEmbeddingProviders(options?: WithTimeout): Promise<FindEmbeddingProvidersResult>;
4868
/**
4969
* Retrieves a list of all the namespaces in the database.
5070
*

0 commit comments

Comments
 (0)