Skip to content

Conversation

@zucchiniEvader
Copy link

@zucchiniEvader zucchiniEvader commented Oct 21, 2025

feat: Add search filter support in knowledge base and vector store implementations

AgentScope Version

[1.0.6dev]

Description

This commit adds search filter support to the knowledge base and vector store implementations in AgentScope. Previously, users could only perform basic similarity searches in vector databases without the ability to filter results based on metadata or other criteria. This limitation made it difficult to retrieve documents with specific characteristics or restrict searches to particular subsets of data.

Changes Made

1. ReAct Agent Integration

  • Added knowledge_filter parameter to the ReActAgent constructor
  • Modified the knowledge retrieval logic to pass the filter to the knowledge base retrieve method

2. Knowledge Base Interface Updates

  • Extended KnowledgeBase.retrieve method to accept a search_filter parameter
  • Updated SimpleKnowledge implementation to pass filters through to the vector store

3. Vector Store Filter Support

  • QdrantStore: Added _format_filters method that converts dictionary filters to Qdrant's models.Filter format
  • MilvusLiteStore: Added _build_expr method that converts filters to Milvus expression strings
  • Both stores now accept a filter parameter in their search methods

4. Document Metadata Enhancement

  • Modified DocMetadata class to accept additional keyword arguments for custom metadata fields
  • Changed from auto-generated @dataclass to custom __init__ method for better flexibility

How to Test

1. Basic Filter Usage

# Create a ReAct agent with knowledge filter
agent = ReActAgent(
    name="FilterAgent",
    knowledge=knowledge_base,
    knowledge_filter={"category": "technical", "difficulty": "beginner"},
    # ... other parameters
)

2. Vector Store Direct Testing

# Test QdrantStore filtering
qdrant_store = QdrantStore(collection_name="test", dimensions=768)
results = await qdrant_store.search(
    query_embedding=embedding,
    limit=5,
    filter={"topic": "machine_learning", "level": "advanced"}
)

# Test MilvusLiteStore filtering  
milvus_store = MilvusLiteStore(collection_name="test", dimensions=768)
results = await milvus_store.search(
    query_embedding=embedding,
    limit=5,
    filter={"author": "John Doe", "published": True}
)

3. Document Metadata Testing

# Create documents with custom metadata
doc_metadata = DocMetadata(
    content=text_block,
    doc_id="doc_1", 
    chunk_id=0,
    total_chunks=5,
    category="tutorial",  # Custom field
    difficulty="beginner"  # Custom field
)

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with pre-commit run --all-files command
  • All tests are passing
  • Docstrings are in Google style
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@zucchiniEvader
Copy link
Author

All tests passed.

@DavdGao DavdGao added the RAG label Oct 23, 2025
@DavdGao DavdGao self-requested a review October 23, 2025 09:42
@cla-assistant
Copy link

cla-assistant bot commented Dec 2, 2025

CLA assistant check
All committers have signed the CLA.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants