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
paramsObjectThe parameters for the query.
params.documents?string | DocumentsOptional documents of the items to add.
params.embeddings?Embedding | EmbeddingsOptional embeddings of the items to add.
params.idsstring | IDsIDs of the items to add.
params.metadatas?Metadata | MetadatasOptional metadata of the items to add.

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: {"$and": ["name": {"$eq": "John Doe"}, "age": {"$gte": 30}]},
whereDocument: {"$contains":"search_string"}
});

Parametersโ€‹

NameTypeDescription
paramsObjectThe parameters for deleting items from the collection.
params.ids?string | IDsOptional ID or array of IDs of items to delete.
params.where?WhereOptional query condition to filter items to delete based on metadata values.
params.whereDocument?WhereDocumentOptional query condition to filter items to delete based on document content.

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
paramsObjectThe parameters for the query.
params.ids?string | IDsOptional IDs of the items to get.
params.include?IncludeEnum[]Optional list of items to include in the response.
params.limit?numberOptional limit on the number of items to get.
params.offset?numberOptional offset on the items to get.
params.where?WhereOptional where clause to filter items by.
params.whereDocument?WhereDocumentOptional where clause to filter items by.

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
paramsObjectThe parameters for the query.
params.metadata?CollectionMetadataOptional new metadata for the collection.
params.name?stringOptional new name for the collection.

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
paramsObjectThe parameters for the query.
params.limit?numberOptional number of results to return (default is 10).

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: {"$and": ["name": {"$eq": "John Doe"}, "age": {"$gte": 30}]},
include: ["metadata", "document"]
});

Example

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

Parametersโ€‹

NameTypeDescription
paramsObjectThe parameters for the query.
params.include?IncludeEnum[]Optional array of fields to include in the result, such as "metadata" and "document".
params.nResults?numberOptional number of results to return (default is 10).
params.queryEmbeddings?Embedding | EmbeddingsOptional query embeddings to use for the search.
params.queryTexts?string | string[]Optional query text(s) to search for in the collection.
params.where?WhereOptional query condition to filter results based on metadata values.
params.whereDocument?WhereDocumentOptional query condition to filter results based on document content.

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
paramsObjectThe parameters for the query.
params.documents?string | DocumentsOptional documents to update.
params.embeddings?Embedding | EmbeddingsOptional embeddings to update.
params.idsstring | IDsThe IDs of the items to update.
params.metadatas?Metadata | MetadatasOptional metadatas to update.

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
paramsObjectThe parameters for the query.
params.documents?string | DocumentsOptional documents of the items to add.
params.embeddings?Embedding | EmbeddingsOptional embeddings of the items to add.
params.idsstring | IDsIDs of the items to add.
params.metadatas?Metadata | MetadatasOptional metadata of the items to add.

Returnsโ€‹

Promise<boolean>

  • The response from the API. True if successful.