Skip to content

Conversation

@Shinu95J
Copy link
Contributor

This PR adds support for recursive filter nesting in the vectordb package, enabling complex boolean expressions like (A OR B) AND (C OR D) in vector search queries.

Previously, the filter abstraction only supported flat conditions within Must/Should/MustNot clauses. While multiple FilterSets could be combined with AND logic, there was no way to express nested boolean groups like:
(status = "active" OR status = "pending") AND (region = "US" OR region = "EU")
Qdrant natively supports nested filter clauses, and this change exposes that capability through the vectordb abstraction.

Changes

  • v1/vectordb/filters.go: Added NestedFilterCondition type that wraps a FilterSet, allowing filters to be used as conditions
  • v1/qdrant/converter.go: Added convertVectorDBNestedFilterCondition to handle the new condition type
  • v1/vectordb/doc.go: Updated Filter Types table to include NestedFilterCondition
  • v1/qdrant/doc.go: Added documentation example for nested filters
// Filter: (status = "active" OR status = "pending") AND (region = "US" OR region = "EU")
filters := []*vectordb.FilterSet{
    vectordb.NewFilterSet(
        vectordb.Must(
            &vectordb.NestedFilterCondition{
                Filter: &vectordb.FilterSet{
                    Should: &vectordb.ConditionSet{
                        Conditions: []vectordb.FilterCondition{
                            vectordb.NewMatch("status", "active"),
                            vectordb.NewMatch("status", "pending"),
                        },
                    },
                },
            },
            &vectordb.NestedFilterCondition{
                Filter: &vectordb.FilterSet{
                    Should: &vectordb.ConditionSet{
                        Conditions: []vectordb.FilterCondition{
                            vectordb.NewMatch("region", "US"),
                            vectordb.NewMatch("region", "EU"),
                        },
                    },
                },
            },
        ),
    ),
}

Example Supported Expressions

Expression Outer Clause Inner Clause
(A OR B) AND (C OR D) Must Should
(A AND B) OR (C AND D) Should Must
(A AND B) AND (C AND D) Must Must

@alphamt alphamt enabled auto-merge (squash) December 30, 2025 14:24
@alphamt alphamt merged commit 2ec510c into main Dec 30, 2025
4 checks passed
@alphamt alphamt deleted the chore/fix_filters branch December 30, 2025 14:25
@alphamt
Copy link
Collaborator

alphamt commented Dec 30, 2025

PR was reviewed on another closed PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants