ChromaCollection class

High-level collection wrapper with automatic embedding generation.

This wrapper provides a more ergonomic API over RecordsResource with:

  • Automatic embedding generation from documents, images, or URIs
  • Convenient query methods that accept text instead of embeddings
  • Validation of input parameters

Example:

final collection = await client.getOrCreateCollection(
  name: 'my-docs',
  embeddingFunction: myEmbedder,
);

// Add documents (embeddings generated automatically)
await collection.add(
  ids: ['id1', 'id2'],
  documents: ['Hello world', 'Goodbye world'],
);

// Query by text (embedding generated automatically)
final results = await collection.query(
  queryTexts: ['greeting'],
  nResults: 5,
);

Constructors

ChromaCollection({required RecordsResource records, required CollectionsResource collections, FunctionsResource? functions, required Collection metadata, EmbeddingFunction? embeddingFunction, DataLoader<Loadable>? dataLoader})
Creates a ChromaCollection wrapper.

Properties

dataLoader DataLoader<Loadable>?
The data loader for loading data from URIs.
final
embeddingFunction EmbeddingFunction?
The embedding function for auto-embedding.
final
hashCode int
The hash code for this object.
no setterinherited
id String
The collection's unique identifier.
no setter
metadata Collection
The collection metadata.
final
name String
The collection's name.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add({required List<String> ids, List<List<double>>? embeddings, List<String>? documents, List<String>? images, List<String>? uris, List<Map<String, dynamic>>? metadatas}) Future<void>
Adds records to the collection.
attachFunction({required String name, required String functionId, required String outputCollection, Map<String, dynamic>? params}) Future<AttachFunctionResponse>
Attaches a function to this collection.
count() Future<int>
Counts records in the collection.
delete({List<String>? ids, Map<String, dynamic>? where, Map<String, dynamic>? whereDocument}) Future<List<String>>
Deletes records from the collection.
detachFunction({required String name, bool? deleteOutput}) Future<DetachFunctionResponse>
Detaches a function from this collection.
get({List<String>? ids, Map<String, dynamic>? where, Map<String, dynamic>? whereDocument, int? limit, int? offset, List<Include> include = const [Include.documents, Include.metadatas]}) Future<GetResponse>
Gets records from the collection.
getFunction({required String name}) Future<GetAttachedFunctionResponse>
Gets details of an attached function by name.
modify({String? newName, Map<String, dynamic>? newMetadata}) Future<Collection>
Updates this collection's name or metadata.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
peek({int limit = 10, List<Include>? include}) Future<GetResponse>
Peeks at the first N records.
query({List<List<double>>? queryEmbeddings, List<String>? queryTexts, List<String>? queryImages, List<String>? queryUris, int nResults = 10, Map<String, dynamic>? where, Map<String, dynamic>? whereDocument, List<Include> include = const [Include.documents, Include.metadatas, Include.distances]}) Future<QueryResponse>
Queries records by similarity.
Performs hybrid search with multiple criteria.
toString() String
A string representation of this object.
inherited
update({required List<String> ids, List<List<double>>? embeddings, List<String>? documents, List<String>? images, List<String>? uris, List<Map<String, dynamic>>? metadatas}) Future<void>
Updates existing records in the collection.
upsert({required List<String> ids, List<List<double>>? embeddings, List<String>? documents, List<String>? images, List<String>? uris, List<Map<String, dynamic>>? metadatas}) Future<void>
Upserts records (insert or update).

Operators

operator ==(Object other) bool
The equality operator.
inherited