Collection Methods
conditional
Start a collection-scoped conditional transaction. Conditional transactions read from a stable snapshot, buffer writes locally, and commit those writes with optimistic conflict detection. Usetxn.commit() for manual transactions, or txn.run(callback, max_retries=3) to rerun the whole callback after retryable optimistic-concurrency conflicts.
Limitations:
- Transactions cannot span collections.
- Nested transaction guarantees are not provided.
txn.query(...)is not supported.- Predicate deletes are not supported; transactional deletes must provide explicit IDs.
- Reading an ID after buffering a write for that ID is an explicit transaction error.
- Only one write per ID can be buffered in a transaction.
- Filter reads protect only returned IDs.
count
Return the number of records in the collection.add
Add records to the collection. Raises:- ValueError: If embeddings and documents are both missing.
- ValueError: If embeddings and documents are both provided.
- ValueError: If lengths of provided fields do not match.
- ValueError: If an ID already exists.
get
Retrieve records from the collection. If no filters are provided, returns records up tolimit starting at
offset.
A Where filter used to filter based on metadata values.
A WhereDocument filter used to filter based on K.DOCUMENT.
Fields to include in results. Can contain “embeddings”, “metadatas”, “documents”, “uris”. Defaults to “metadatas” and “documents”.
peek
Return the firstlimit records from the collection.
Returns: Retrieved records and requested fields.
query
Query for the K nearest neighbor records in the collection. This is a batch query API. Multiple queries can be performed at once by providing multiple embeddings, texts, or images.ids, where, where_document, and include parameters are applied
to all queries.
Document content filter.
Fields to include in results. Can contain “embeddings”, “metadatas”, “documents”, “uris”, “distances”. Defaults to “metadatas”, “documents”, “distances”.
- ValueError: If no query input is provided.
- ValueError: If multiple query input types are provided.
modify
Update collection name, metadata, or configuration.update
Update existing records by ID. Records are provided in columnar format. If provided, theembeddings, metadatas, documents, and uris lists must be the same length.
Entries in each list correspond to the same record.
embeddings are not provided, the embeddings will be computed based on documents using the collection’s embedding function.
upsert
Create or update records by ID.delete
Delete records by ID or filters. All documents that match theids or where and where_document filters will be deleted.
Document content filter.
- ValueError: If no IDs or filters are provided.
Types
GetResult
Result payload for collection.get() operations. The returned records are in columnar form. Corresponding entries in each list correspond to the same record.include param
when making the get() operation.
Properties
QueryResult
Result payload for collection.query() operations. The returned records are batches of records in columnar form.include param
when making the query() operation.
Properties