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

source

pub fn id(&self) -> &str

Get the UUID of the collection.

source

pub fn name(&self) -> &str

Get the name of the collection.

source

pub fn metadata(&self) -> Option<&Map<String, Value>>

Get the metadata of the collection.

source

pub fn count(&self) -> Result<usize>

The total number of embeddings added to the database.

source

pub fn modify( &self, name: Option<&str>, metadata: Option<&Map<String, Value>> ) -> Result<()>

Modify the name/metadata of a collection.

§Arguments
  • name - The new name of the collection. Must be unique.
  • metadata - The new metadata of the collection. Must be a JSON object with keys and values that are either numbers, strings or floats.
§Errors
  • If the collection name is invalid
source

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
source

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
source

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.
source

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
source

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
source

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.
source

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. Optional
  • where_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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for ChromaCollection

source§

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§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,