Skip to content

[Feature Request] Add runtime filter support to MilvusEmbeddingRetriever #67

Description

@kukjun

Problem

MilvusEmbeddingRetriever doesn't support runtime filtering, unlike other Haystack retrievers (Elasticsearch, InMemory, etc.).

Current signature:

def run(self, query_embedding: List[float], top_k: int)

Expected signature:

def run(self, query_embedding: List[float], top_k: int, filters: Optional[Dict[str, Any]] = None)
Example Usage
retriever = MilvusEmbeddingRetriever(document_store=document_store)

filters = {
    "operator": "AND",
    "conditions": [
        {"field": "meta.category", "operator": "==", "value": "diabetes"},
        {"field": "meta.year", "operator": ">=", "value": 2020}
    ]
}


results = retriever.run(query_embedding=embedding, filters=filters)

Why This Matters

  • Consistency: All other vector stores support this - Milvus shouldn't be an exception
  • Performance: Database-level filtering is far more efficient than post-retrieval filtering in Python
  • Interoperability: Enables seamless switching between vector databases
  • Use Cases: Multi-tenancy, category filtering, time-based search, etc.

Implementation Approaches

I'm considering two approaches and would appreciate maintainer input:

1. Milvus-Native

Convert Haystack filters to Milvus boolean expressions:

# {"field": "meta.category", "operator": "==", "value": "diabetes"}
# → "category == 'diabetes'"

2. Unified Integration

Align with a standardized filter format that works across multiple vector databases (Milvus, Pinecone, Weaviate, Qdrant), making the entire Haystack ecosystem more consistent.

Technical Details

Milvus supports filtering via Collection.search(expr=...)
pymilvus already provides this functionality
Just need to bridge Haystack's filter format to Milvus expressions

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions