Struct chromadb::v1::collection::ChromaCollection
source · pub struct ChromaCollection { /* private fields */ }
Expand description
A collection representation for interacting with the associated ChromaDB collection.
Implementations§
source§impl ChromaCollection
impl ChromaCollection
sourcepub fn modify(
&self,
name: Option<&str>,
metadata: Option<&Map<String, Value>>
) -> Result<()>
pub fn modify( &self, name: Option<&str>, metadata: Option<&Map<String, Value>> ) -> Result<()>
sourcepub fn add(
&self,
collection_entries: CollectionEntries<'_>,
embedding_function: Option<Box<dyn EmbeddingFunction>>
) -> Result<Value>
pub fn add( &self, collection_entries: CollectionEntries<'_>, embedding_function: Option<Box<dyn EmbeddingFunction>> ) -> Result<Value>
Add embeddings to the data store. Ignore the insert if the ID already exists.
§Arguments
ids
- The ids to associate with the embeddings.embeddings
- The embeddings to add. If None, embeddings will be computed based on the documents using the provided embedding_function. Optional.metadata
- The metadata to associate with the embeddings. When querying, you can filter on this metadata. Optional.documents
- The documents to associate with the embeddings. Optional.embedding_function
- The function to use to compute the embeddings. If None, embeddings must be provided. Optional.
§Errors
- If you don’t provide either embeddings or documents
- If the length of ids, embeddings, metadatas, or documents don’t match
- If you provide duplicates in ids, empty ids
- If you provide documents and don’t provide an embedding function when embeddings is None
- If you provide an embedding function and don’t provide documents
- If you provide both embeddings and embedding_function
sourcepub fn upsert(
&self,
collection_entries: CollectionEntries<'_>,
embedding_function: Option<Box<dyn EmbeddingFunction>>
) -> Result<Value>
pub fn upsert( &self, collection_entries: CollectionEntries<'_>, embedding_function: Option<Box<dyn EmbeddingFunction>> ) -> Result<Value>
Add embeddings to the data store. Update the entry if an ID already exists.
§Arguments
ids
- The ids to associate with the embeddings.embeddings
- The embeddings to add. If None, embeddings will be computed based on the documents using the provided embedding_function. Optional.metadata
- The metadata to associate with the embeddings. When querying, you can filter on this metadata. Optional.documents
- The documents to associate with the embeddings. Optional.embedding_function
- The function to use to compute the embeddings. If None, embeddings must be provided. Optional.
§Errors
- If you don’t provide either embeddings or documents
- If the length of ids, embeddings, metadatas, or documents don’t match
- If you provide duplicates in ids, empty ids
- If you provide documents and don’t provide an embedding function when embeddings is None
- If you provide an embedding function and don’t provide documents
- If you provide both embeddings and embedding_function
sourcepub fn get(&self, get_options: GetOptions) -> Result<GetResult>
pub fn get(&self, get_options: GetOptions) -> Result<GetResult>
Get embeddings and their associated data from the collection. If no ids or filter is provided returns all embeddings up to limit starting at offset.
§Arguments
ids
- The ids of the embeddings to get. Optional..where_metadata
- Used to filter results by metadata. E.g.{ "$and": [{"foo": "bar"}, {"price": {"$gte": 4.20}}] }
. See https://docs.trychroma.com/usage-guide#filtering-by-metadata for more information on metadata filters. Optional.limit
- The maximum number of documents to return. Optional.offset
- The offset to start returning results from. Useful for paging results with limit. Optional.where_document
- Used to filter by the documents. E.g. {“$contains”: “hello”}. See https://docs.trychroma.com/usage-guide#filtering-by-document-contents for more information on document content filters. Optional.include
- A list of what to include in the results. Can contain"embeddings"
,"metadatas"
,"documents"
. Ids are always included. Defaults to["metadatas", "documents"]
. Optional.
sourcepub fn update(
&self,
collection_entries: CollectionEntries<'_>,
embedding_function: Option<Box<dyn EmbeddingFunction>>
) -> Result<bool>
pub fn update( &self, collection_entries: CollectionEntries<'_>, embedding_function: Option<Box<dyn EmbeddingFunction>> ) -> Result<bool>
Update the embeddings, metadatas or documents for provided ids.
§Arguments
ids
- The ids to associate with the embeddings.embeddings
- The embeddings to add. If None, embeddings will be computed based on the documents using the provided embedding_function. Optional.metadata
- The metadata to associate with the embeddings. When querying, you can filter on this metadata. Optional.documents
- The documents to associate with the embeddings. Optional.embedding_function
- The function to use to compute the embeddings. If None, embeddings must be provided. Optional.
§Errors
- If the length of ids, embeddings, metadatas, or documents don’t match
- If you provide duplicates in ids, empty ids
- If you provide documents and don’t provide an embedding function when embeddings is None
- If you provide an embedding function and don’t provide documents
- If you provide both embeddings and embedding_function
sourcepub fn query(
&self,
query_options: QueryOptions<'_>,
embedding_function: Option<Box<dyn EmbeddingFunction>>
) -> Result<QueryResult>
pub fn query( &self, query_options: QueryOptions<'_>, embedding_function: Option<Box<dyn EmbeddingFunction>> ) -> Result<QueryResult>
Get the n_results nearest neighbor embeddings for provided query_embeddings or query_texts.
§Arguments
query_embeddings
- The embeddings to get the closest neighbors of. Optional.query_texts
- The document texts to get the closest neighbors of. Optional.n_results
- The number of neighbors to return for each query_embedding or query_texts. Optional.where_metadata
- Used to filter results by metadata. E.g. {“$and”: [“color” : “red”, “price”: {“$gte”: 4.20}]}. Optional.where_document
- Used to filter results by documents. E.g. {$contains: “some text”}. Optional.include
- A list of what to include in the results. Can contain “embeddings”, “metadatas”, “documents”, “distances”. Ids are always included. Defaults to [“metadatas”, “documents”, “distances”]. Optional.embedding_function
- The function to use to compute the embeddings. If None, embeddings must be provided. Optional.
§Errors
- If you don’t provide either query_embeddings or query_texts
- If you provide both query_embeddings and query_texts
- If you provide query_texts and don’t provide an embedding function when embeddings is None
sourcepub fn peek(&self, limit: usize) -> Result<GetResult>
pub fn peek(&self, limit: usize) -> Result<GetResult>
Get the first entries in the collection up to the limit
§Arguments
limit
- The number of entries to return.
sourcepub fn delete(
&self,
ids: Option<Vec<&str>>,
where_metadata: Option<Value>,
where_document: Option<Value>
) -> Result<Vec<String>>
pub fn delete( &self, ids: Option<Vec<&str>>, where_metadata: Option<Value>, where_document: Option<Value> ) -> Result<Vec<String>>
Delete the embeddings based on ids and/or a where filter. Deletes all the entries if None are provided
§Arguments
ids
- The ids of the embeddings to delete. Optionalwhere_metadata
- Used to filter deletion by metadata. E.g. {“$and”: [“color” : “red”, “price”: {“$gte”: 4.20}]}. Optional.where_document
- Used to filter the deletion by the document content. E.g. {$contains: “some text”}. Optional.. Optional.
Trait Implementations§
source§impl Debug for ChromaCollection
impl Debug for ChromaCollection
source§impl<'de> Deserialize<'de> for ChromaCollection
impl<'de> Deserialize<'de> for ChromaCollection
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ChromaCollection
impl RefUnwindSafe for ChromaCollection
impl Send for ChromaCollection
impl Sync for ChromaCollection
impl Unpin for ChromaCollection
impl UnwindSafe for ChromaCollection
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more