pub enum Key {
Document,
Embedding,
Metadata,
Score,
MetadataField(String),
}Expand description
Represents a field key in search queries.
Used for both selecting fields to return and building filter expressions. Predefined keys access special fields, while custom keys access metadata.
§Predefined Keys
Key::Document- Document text content (#document)Key::Embedding- Vector embeddings (#embedding)Key::Metadata- All metadata fields (#metadata)Key::Score- Search scores (#score)
§Custom Keys
Use Key::field() or Key::from() to reference metadata fields:
use chroma_types::operator::Key;
let key = Key::field("author");
let key = Key::from("title");§Examples
§Building filters
use chroma_types::operator::Key;
// Equality
let filter = Key::field("status").eq("published");
// Comparisons
let filter = Key::field("year").gte(2020);
let filter = Key::field("score").lt(0.9);
// Set operations
let filter = Key::field("category").is_in(vec!["tech", "science"]);
let filter = Key::field("status").not_in(vec!["deleted", "archived"]);
// Document content
let filter = Key::Document.contains("machine learning");
let filter = Key::Document.regex(r"\bAPI\b");
// Combining filters
let filter = Key::field("status").eq("published")
& Key::field("year").gte(2020);§Selecting fields
use chroma_types::plan::SearchPayload;
use chroma_types::operator::Key;
let search = SearchPayload::default()
.select([
Key::Document,
Key::Score,
Key::field("title"),
Key::field("author"),
]);Variants§
Implementations§
Source§impl Key
impl Key
Sourcepub fn field(name: impl Into<String>) -> Key
pub fn field(name: impl Into<String>) -> Key
Creates a Key for a custom metadata field.
§Examples
use chroma_types::operator::Key;
let status = Key::field("status");
let year = Key::field("year");
let author = Key::field("author");Sourcepub fn eq<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
pub fn eq<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
Creates an equality filter: field == value.
§Examples
use chroma_types::operator::Key;
// String equality
let filter = Key::field("status").eq("published");
// Numeric equality
let filter = Key::field("count").eq(42);
// Boolean equality
let filter = Key::field("featured").eq(true);Sourcepub fn ne<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
pub fn ne<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
Creates an inequality filter: field != value.
§Examples
use chroma_types::operator::Key;
let filter = Key::field("status").ne("deleted");
let filter = Key::field("count").ne(0);Sourcepub fn gt<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
pub fn gt<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
Creates a greater-than filter: field > value (numeric only).
§Examples
use chroma_types::operator::Key;
let filter = Key::field("score").gt(0.5);
let filter = Key::field("year").gt(2020);Sourcepub fn gte<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
pub fn gte<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
Creates a greater-than-or-equal filter: field >= value (numeric only).
§Examples
use chroma_types::operator::Key;
let filter = Key::field("score").gte(0.5);
let filter = Key::field("year").gte(2020);Sourcepub fn lt<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
pub fn lt<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
Creates a less-than filter: field < value (numeric only).
§Examples
use chroma_types::operator::Key;
let filter = Key::field("score").lt(0.9);
let filter = Key::field("year").lt(2025);Sourcepub fn lte<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
pub fn lte<T>(self, value: T) -> Wherewhere
T: Into<MetadataValue>,
Creates a less-than-or-equal filter: field <= value (numeric only).
§Examples
use chroma_types::operator::Key;
let filter = Key::field("score").lte(0.9);
let filter = Key::field("year").lte(2024);Sourcepub fn is_in<I, T>(self, values: I) -> Where
pub fn is_in<I, T>(self, values: I) -> Where
Creates a set membership filter: field IN values.
Accepts any iterator (Vec, array, slice, etc.).
§Examples
use chroma_types::operator::Key;
// With Vec
let filter = Key::field("year").is_in(vec![2023, 2024, 2025]);
// With array
let filter = Key::field("category").is_in(["tech", "science", "math"]);
// With owned strings
let categories = vec!["tech".to_string(), "science".to_string()];
let filter = Key::field("category").is_in(categories);Sourcepub fn not_in<I, T>(self, values: I) -> Where
pub fn not_in<I, T>(self, values: I) -> Where
Creates a set exclusion filter: field NOT IN values.
Accepts any iterator (Vec, array, slice, etc.).
§Examples
use chroma_types::operator::Key;
// Exclude deleted and archived
let filter = Key::field("status").not_in(vec!["deleted", "archived"]);
// Exclude specific years
let filter = Key::field("year").not_in(vec![2019, 2020]);Sourcepub fn contains<S>(self, text: S) -> Where
pub fn contains<S>(self, text: S) -> Where
Creates a substring filter (case-sensitive, document content only).
Note: Currently only works with Key::Document. Pattern must have at least
3 literal characters for accurate results.
§Examples
use chroma_types::operator::Key;
let filter = Key::Document.contains("machine learning");
let filter = Key::Document.contains("API");Sourcepub fn not_contains<S>(self, text: S) -> Where
pub fn not_contains<S>(self, text: S) -> Where
Creates a negative substring filter (case-sensitive, document content only).
Note: Currently only works with Key::Document.
§Examples
use chroma_types::operator::Key;
let filter = Key::Document.not_contains("deprecated");
let filter = Key::Document.not_contains("beta");Sourcepub fn regex<S>(self, pattern: S) -> Where
pub fn regex<S>(self, pattern: S) -> Where
Creates a regex filter (case-sensitive, document content only).
Note: Currently only works with Key::Document. Pattern must have at least
3 literal characters for accurate results.
§Examples
use chroma_types::operator::Key;
// Match whole word "API"
let filter = Key::Document.regex(r"\bAPI\b");
// Match version pattern
let filter = Key::Document.regex(r"v\d+\.\d+\.\d+");Sourcepub fn not_regex<S>(self, pattern: S) -> Where
pub fn not_regex<S>(self, pattern: S) -> Where
Creates a negative regex filter (case-sensitive, document content only).
Note: Currently only works with Key::Document.
§Examples
use chroma_types::operator::Key;
// Exclude beta versions
let filter = Key::Document.not_regex(r"beta");
// Exclude test documents
let filter = Key::Document.not_regex(r"\btest\b");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Key
impl<'de> Deserialize<'de> for Key
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Key, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Key, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Ord for Key
impl Ord for Key
Source§impl PartialOrd for Key
impl PartialOrd for Key
Source§impl Serialize for Key
impl Serialize for Key
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Eq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.