Skip to content

Commit

Permalink
Kg add vectorize doc (#42)
Browse files Browse the repository at this point in the history
* Added VectorizeDoc

* api report + added couple public tags
  • Loading branch information
toptobes authored May 24, 2024
1 parent 7d26f2d commit b1f71cc
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
12 changes: 11 additions & 1 deletion etc/astra-db-ts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export type Caller = [name: string, version?: string];
// @public
export class Collection<Schema extends SomeDoc = SomeDoc> {
// Warning: (ae-forgotten-export) The symbol "DataAPIHttpClient" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "CollectionSpawnOptions" needs to be exported by the entry point index.d.ts
//
// @internal
constructor(db: Db, httpClient: DataAPIHttpClient, name: string, opts: CollectionSpawnOptions | undefined);
Expand Down Expand Up @@ -232,6 +231,12 @@ export interface CollectionOptions<Schema extends SomeDoc> {
vector?: VectorOptions;
}

// @public
export interface CollectionSpawnOptions extends WithNamespace {
defaultMaxTimeMS?: number;
embeddingApiKey?: string;
}

// @public
export abstract class CommandEvent {
// Warning: (ae-forgotten-export) The symbol "DataAPIRequestInfo" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -1170,6 +1175,11 @@ export interface VectorDoc {
$vector?: number[];
}

// @public
export interface VectorizeDoc {
$vectorize: string;
}

// @alpha
export interface VectorizeServiceOptions {
authentication?: Record<string, string | undefined>;
Expand Down
2 changes: 1 addition & 1 deletion src/data-api/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { DeleteManyResult } from '@/src/data-api/types/delete/delete-many';
import type { UpdateManyResult } from '@/src/data-api/types/update/update-many';
import type { BulkWriteResult } from '@/src/data-api/types/misc/bulk-write';
import type { CuratedAPIResponse, RawDataAPIResponse, ResponseInfo } from '@/src/api';
import { SomeDoc } from '@/src/data-api/document';
import { SomeDoc } from '@/src/data-api/types/document';

/**
* An object representing a single "soft" (2XX) error returned from the Data API, typically with an error code and a
Expand Down
1 change: 0 additions & 1 deletion src/data-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

export * from './collection';
export * from './cursor';
export * from './document';
export { Db } from './db';
export {
DataAPITimeoutError,
Expand Down
2 changes: 2 additions & 0 deletions src/data-api/types/collections/spawn-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { WithNamespace } from '@/src/data-api';

/**
* Options for spawning a new collection.
*
* @public
*/
export interface CollectionSpawnOptions extends WithNamespace {
/**
Expand Down
28 changes: 27 additions & 1 deletion src/data-api/document.ts → src/data-api/types/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
export type SomeDoc = Record<string, any>;

/**
* Base type for a document that wishes to leverage vector capabilities.
* Base type for a document that wishes to leverage raw vector capabilities.
*
* @example
* ```
* export interface Idea extends VectorDoc {
*   category: string,
*   idea: string,
* }
*
* db.collection<Idea>('ideas').insertOne({
*   category: 'doors',
*   idea: 'Upside down doors',
*   $vector: [.23, .05, .95, .83, .42],
* });
Expand All @@ -46,3 +48,27 @@ export interface VectorDoc {
*/
$vector?: number[],
}

/**
* Base type for a document that wishes to leverage automatic vectorization (assuming the collection is vectorize-enabled).
*
* @example
* ```
* export interface Idea extends VectorizeDoc {
*   category: string,
* }
*
* db.collection<Idea>('ideas').insertOne({
*   category: 'doors',
*   $vectorize: 'Upside down doors',
* });
* ```
*
* @public
*/
export interface VectorizeDoc {
/**
* A string field to be automatically vectorized
*/
$vectorize: string,
}
2 changes: 2 additions & 0 deletions src/data-api/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export { CreateCollectionOptions } from './collections/create-collection';
export { ListCollectionsOptions, FullCollectionInfo } from './collections/list-collection';
export * from './collections/drop-collection';
export * from './collections/command';
export * from './collections/spawn-collection';
export { DeleteManyResult } from './delete/delete-many';
export { DeleteOneResult, DeleteOneOptions } from './delete/delete-one';
export { FindOptions } from './find/find';
Expand All @@ -37,4 +38,5 @@ export * from './common';
export * from './dot-notation';
export * from './filter';
export * from './update-filter';
export * from './document';
export { WithId, MaybeId, FoundDoc, NoId, Flatten, IdOf } from './utils';
2 changes: 1 addition & 1 deletion tests/typing/collections/prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

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

export interface TestSchema extends VectorDoc {
Expand Down

0 comments on commit b1f71cc

Please sign in to comment.