Collection
The Collection class represents a collection of embeddings in Chroma. It provides methods for adding, querying, updating, and deleting embeddings.
Properties
The name of the collection
The unique identifier of the collection
CollectionMetadata | undefined
Optional metadata associated with the collection
The embedding function used by this collection
CollectionConfiguration | undefined
The collection’s configuration
Methods
add
Add items to the collection.
Parameters:
Show AddRecordsParams properties
IDs of the items to add. Can be a single string or an array of strings
Optional embeddings of the items to add. Required if documents are not provided
Optional metadata of the items to add
Optional documents of the items to add. Required if embeddings are not provided
Returns: Promise that resolves when items are added
You must provide either embeddings or documents (which will be embedded automatically using the collection’s embedding function).
Example:
query
Performs a query on the collection using the specified parameters.
Parameters:
QueryRecordsParams
required
Show QueryRecordsParams properties
Optional query embeddings to use for the search
Optional query text(s) to search for in the collection
Number of results to return
Optional query condition to filter results based on metadata values
Optional query condition to filter results based on document content
Optional array of fields to include in the result (e.g., [“embeddings”, “metadatas”, “documents”, “distances”])
Optional IDs to filter on before querying
Returns: Promise resolving to MultiQueryResponse
Throws: Error if neither queryEmbeddings nor queryTexts are provided
You must provide either queryEmbeddings or queryTexts.
Example with query text:
Example with query embeddings:
get
Get items from the collection.
Parameters:
Show BaseGetParams properties
Optional IDs of the items to get
Optional where clause to filter items by
Optional limit on the number of items to get
Optional offset on the items to get
Optional list of items to include in the response
Optional where clause to filter items by document content
Returns: Promise resolving to GetResponse
Example:
update
Update items in the collection.
Parameters:
UpdateRecordsParams
required
Show UpdateRecordsParams properties
IDs of the items to update
Optional embeddings of the items to update
Optional metadata of the items to update
Optional documents of the items to update
Returns: Promise that resolves when items are updated
Example:
upsert
Upsert (insert or update) items to the collection.
Parameters:
UpsertRecordsParams
required
Same as AddRecordsParams
Returns: Promise that resolves when items are upserted
Example:
delete
Deletes items from the collection.
Parameters:
Show DeleteParams properties
Optional ID or array of IDs of items to delete
Optional query condition to filter items to delete based on metadata values
Optional query condition to filter items to delete based on document content
Returns: Promise that resolves when items are deleted
Throws: Error if there is an issue deleting items
Example:
count
Count the number of items in the collection.
Returns: Promise resolving to the number of items in the collection
Example:
peek
Peek inside the collection to get a sample of items.
Parameters:
Show PeekParams properties
Number of results to return
Returns: Promise resolving to the query results
Throws: Error if there is an issue executing the query
Example:
modify
Modify the collection name or metadata.
Parameters:
Optional new name for the collection
Optional new metadata for the collection
UpdateCollectionConfiguration
Optional new configuration for the collection
Returns: Promise resolving to the updated collection parameters
Example:
fork
Forks the collection into a new collection with a new name.
Parameters:
ForkCollectionParams
required
Show ForkCollectionParams properties
The name for the new forked collection
Returns: Promise resolving to the new forked Collection object
Throws: Error if there is an issue forking the collection
Example: