Fix parsing

This commit is contained in:
Mubelotix
2025-07-08 10:01:50 +02:00
parent 40e7284d70
commit 2d45124d9b
2 changed files with 9 additions and 6 deletions

View File

@ -241,7 +241,7 @@ impl<'a> Filter<'a> {
let attribute = fid.value();
if matching_features(attribute, &filterable_attributes_rules)
.is_some_and(|(_, features)| features.is_filterable())
.is_some_and(|(_, features)| features.is_filterable()) || VectorFilter::matches(attribute)
{
continue;
}
@ -546,7 +546,12 @@ impl<'a> Filter<'a> {
}
FilterCondition::Condition { fid, op } => {
let value = fid.value();
if VectorFilter::matches(value, op) {
if VectorFilter::matches(value) {
if !matches!(op, Condition::Exists) {
return Err(Error::UserError(UserError::InvalidFilter(
String::from("Vector filter can only be used with the `exists` operator"),
)));
}
let vector_filter = VectorFilter::parse(value)?;
return vector_filter.evaluate(rtxn, index, universe);
}

View File

@ -1,4 +1,3 @@
use filter_parser::Condition;
use roaring::RoaringBitmap;
use crate::error::{Error, UserError};
@ -13,15 +12,14 @@ pub(super) struct VectorFilter<'a> {
}
impl<'a> VectorFilter<'a> {
pub(super) fn matches(value: &str, op: &Condition) -> bool {
matches!(op, Condition::Exists) && (value.starts_with("_vectors.") || value == "_vectors")
pub(super) fn matches(value: &str) -> bool {
value.starts_with("_vectors.") || value == "_vectors"
}
/// Parses a vector filter string.
///
/// Valid formats:
/// - `_vectors`
/// - `_vectors.userProvided`
/// - `_vectors.{embedder_name}`
/// - `_vectors.{embedder_name}.userProvided`
/// - `_vectors.{embedder_name}.fragments.{fragment_name}`