Skip to main content

Class: Collection

Properties

id

id: string


metadata

metadata: undefined | CollectionMetadata


name

name: string

Methods

add

add(params): Promise<AddResponse>

Add items to the collection

Example

const response = await collection.add({
ids: ["id1", "id2"],
embeddings: [[1, 2, 3], [4, 5, 6]],
metadatas: [{ "key": "value" }, { "key": "value" }],
documents: ["document1", "document2"]
});

Parameters

NameTypeDescription
paramsAddParamsThe parameters for the query.

Returns

Promise<AddResponse>

  • The response from the API. True if successful.

count

count(): Promise<number>

Count the number of items in the collection

Example

const response = await collection.count();

Returns

Promise<number>

  • The response from the API.

delete

delete(params?): Promise<string[]>

Deletes items from the collection.

Throws

If there is an issue deleting items from the collection.

Example

const results = await collection.delete({
ids: "some_id",
where: {"name": {"$eq": "John Doe"}},
whereDocument: {"$contains":"search_string"}
});

Parameters

NameTypeDescription
paramsDeleteParamsThe parameters for deleting items from the collection.

Returns

Promise<string[]>

A promise that resolves to the IDs of the deleted items.


get

get(params?): Promise<GetResponse>

Get items from the collection

Example

const response = await collection.get({
ids: ["id1", "id2"],
where: { "key": "value" },
limit: 10,
offset: 0,
include: ["embeddings", "metadatas", "documents"],
whereDocument: { $contains: "value" },
});

Parameters

NameTypeDescription
paramsGetParamsThe parameters for the query.

Returns

Promise<GetResponse>

  • The response from the server.

modify

modify(params?): Promise<void>

Modify the collection name or metadata

Example

const response = await collection.modify({
name: "new name",
metadata: { "key": "value" },
});

Parameters

NameTypeDescription
paramsModifyCollectionParamsThe parameters for the query.

Returns

Promise<void>

  • The response from the API.

peek

peek(params?): Promise<GetResponse>

Peek inside the collection

Throws

If there is an issue executing the query.

Example

const results = await collection.peek({
limit: 10
});

Parameters

NameTypeDescription
paramsPeekParamsThe parameters for the query.

Returns

Promise<GetResponse>

A promise that resolves to the query results.


query

query(params): Promise<QueryResponse>

Performs a query on the collection using the specified parameters.

Throws

If there is an issue executing the query.

Example

// Query the collection using embeddings
const results = await collection.query({
queryEmbeddings: [[0.1, 0.2, ...], ...],
nResults: 10,
where: {"name": {"$eq": "John Doe"}},
include: ["metadata", "document"]
});

Example

// Query the collection using query text
const results = await collection.query({
queryTexts: "some text",
nResults: 10,
where: {"name": {"$eq": "John Doe"}},
include: ["metadata", "document"]
});

Parameters

NameTypeDescription
paramsQueryParamsThe parameters for the query.

Returns

Promise<QueryResponse>

A promise that resolves to the query results.


update

update(params): Promise<boolean>

Update the embeddings, documents, and/or metadatas of existing items

Example

const response = await collection.update({
ids: ["id1", "id2"],
embeddings: [[1, 2, 3], [4, 5, 6]],
metadatas: [{ "key": "value" }, { "key": "value" }],
documents: ["new document 1", "new document 2"],
});

Parameters

NameTypeDescription
paramsAddParamsThe parameters for the query.

Returns

Promise<boolean>

  • The API Response. True if successful. Else, error.

upsert

upsert(params): Promise<boolean>

Upsert items to the collection

Example

const response = await collection.upsert({
ids: ["id1", "id2"],
embeddings: [[1, 2, 3], [4, 5, 6]],
metadatas: [{ "key": "value" }, { "key": "value" }],
documents: ["document1", "document2"],
});

Parameters

NameTypeDescription
paramsAddParamsThe parameters for the query.

Returns

Promise<boolean>

  • The response from the API. True if successful.