Skip to content

Conversation

@Shinu95J
Copy link
Contributor

@Shinu95J Shinu95J commented Dec 29, 2025

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

Signed-off-by: Shinu Joseph <shinu.joseph@aleph-alpha.com>
@alphamt
Copy link
Collaborator

alphamt commented Dec 30, 2025

Hey @Shinu95J I think there are some unrelated changes in the MR

@Shinu95J Shinu95J closed this Dec 30, 2025
@Shinu95J Shinu95J deleted the chore/improve_filtering branch December 30, 2025 13:32
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