Skip to content

Commit b1f71cc

Browse files
authored
Kg add vectorize doc (#42)
* Added VectorizeDoc * api report + added couple public tags
1 parent 7d26f2d commit b1f71cc

File tree

7 files changed

+44
-5
lines changed

7 files changed

+44
-5
lines changed

etc/astra-db-ts.api.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ export type Caller = [name: string, version?: string];
175175
// @public
176176
export class Collection<Schema extends SomeDoc = SomeDoc> {
177177
// Warning: (ae-forgotten-export) The symbol "DataAPIHttpClient" needs to be exported by the entry point index.d.ts
178-
// Warning: (ae-forgotten-export) The symbol "CollectionSpawnOptions" needs to be exported by the entry point index.d.ts
179178
//
180179
// @internal
181180
constructor(db: Db, httpClient: DataAPIHttpClient, name: string, opts: CollectionSpawnOptions | undefined);
@@ -232,6 +231,12 @@ export interface CollectionOptions<Schema extends SomeDoc> {
232231
vector?: VectorOptions;
233232
}
234233

234+
// @public
235+
export interface CollectionSpawnOptions extends WithNamespace {
236+
defaultMaxTimeMS?: number;
237+
embeddingApiKey?: string;
238+
}
239+
235240
// @public
236241
export abstract class CommandEvent {
237242
// Warning: (ae-forgotten-export) The symbol "DataAPIRequestInfo" needs to be exported by the entry point index.d.ts
@@ -1170,6 +1175,11 @@ export interface VectorDoc {
11701175
$vector?: number[];
11711176
}
11721177

1178+
// @public
1179+
export interface VectorizeDoc {
1180+
$vectorize: string;
1181+
}
1182+
11731183
// @alpha
11741184
export interface VectorizeServiceOptions {
11751185
authentication?: Record<string, string | undefined>;

src/data-api/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { DeleteManyResult } from '@/src/data-api/types/delete/delete-many';
1717
import type { UpdateManyResult } from '@/src/data-api/types/update/update-many';
1818
import type { BulkWriteResult } from '@/src/data-api/types/misc/bulk-write';
1919
import type { CuratedAPIResponse, RawDataAPIResponse, ResponseInfo } from '@/src/api';
20-
import { SomeDoc } from '@/src/data-api/document';
20+
import { SomeDoc } from '@/src/data-api/types/document';
2121

2222
/**
2323
* An object representing a single "soft" (2XX) error returned from the Data API, typically with an error code and a

src/data-api/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
export * from './collection';
1717
export * from './cursor';
18-
export * from './document';
1918
export { Db } from './db';
2019
export {
2120
DataAPITimeoutError,

src/data-api/types/collections/spawn-collection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { WithNamespace } from '@/src/data-api';
1616

1717
/**
1818
* Options for spawning a new collection.
19+
*
20+
* @public
1921
*/
2022
export interface CollectionSpawnOptions extends WithNamespace {
2123
/**

src/data-api/document.ts renamed to src/data-api/types/document.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424
export type SomeDoc = Record<string, any>;
2525

2626
/**
27-
* Base type for a document that wishes to leverage vector capabilities.
27+
* Base type for a document that wishes to leverage raw vector capabilities.
2828
*
2929
* @example
3030
* ```
3131
* export interface Idea extends VectorDoc {
32+
*   category: string,
3233
*   idea: string,
3334
* }
3435
*
3536
* db.collection<Idea>('ideas').insertOne({
37+
*   category: 'doors',
3638
*   idea: 'Upside down doors',
3739
*   $vector: [.23, .05, .95, .83, .42],
3840
* });
@@ -46,3 +48,27 @@ export interface VectorDoc {
4648
*/
4749
$vector?: number[],
4850
}
51+
52+
/**
53+
* Base type for a document that wishes to leverage automatic vectorization (assuming the collection is vectorize-enabled).
54+
*
55+
* @example
56+
* ```
57+
* export interface Idea extends VectorizeDoc {
58+
*   category: string,
59+
* }
60+
*
61+
* db.collection<Idea>('ideas').insertOne({
62+
*   category: 'doors',
63+
*   $vectorize: 'Upside down doors',
64+
* });
65+
* ```
66+
*
67+
* @public
68+
*/
69+
export interface VectorizeDoc {
70+
/**
71+
* A string field to be automatically vectorized
72+
*/
73+
$vectorize: string,
74+
}

src/data-api/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export { CreateCollectionOptions } from './collections/create-collection';
1818
export { ListCollectionsOptions, FullCollectionInfo } from './collections/list-collection';
1919
export * from './collections/drop-collection';
2020
export * from './collections/command';
21+
export * from './collections/spawn-collection';
2122
export { DeleteManyResult } from './delete/delete-many';
2223
export { DeleteOneResult, DeleteOneOptions } from './delete/delete-one';
2324
export { FindOptions } from './find/find';
@@ -37,4 +38,5 @@ export * from './common';
3738
export * from './dot-notation';
3839
export * from './filter';
3940
export * from './update-filter';
41+
export * from './document';
4042
export { WithId, MaybeId, FoundDoc, NoId, Flatten, IdOf } from './utils';

tests/typing/collections/prelude.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import { Collection, VectorDoc } from '@/src/data-api';
16-
import { SomeDoc } from '@/src/data-api/document';
16+
import { SomeDoc } from '@/src/data-api/types/document';
1717
import { Db } from '@/src/data-api/db';
1818

1919
export interface TestSchema extends VectorDoc {

0 commit comments

Comments
 (0)