Merge pull request #292 from ggozad/fix/fix-filter

Remove filter parameter from search and list_documents tools
This commit is contained in:
Yiorgis Gozadinos 2026-03-03 11:12:22 +02:00 committed by GitHub
commit a9583abd76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 21 deletions

View file

@ -1,6 +1,10 @@
# Changelog
## [Unreleased]
### Fixed
- **Search tool regression**: Removed LLM-facing `filter` parameter from search and list_documents tools. The SQL WHERE clause description confused LLMs, degrading QA accuracy. Document filtering is now handled programmatically via `base_filter` and `state.document_filter`
## [0.32.2] - 2026-02-28
### Fixed

View file

@ -140,19 +140,17 @@ def create_skill(
ctx: RunContext[SkillRunDeps],
limit: int | None = None,
offset: int | None = None,
filter: str | None = None,
) -> list[dict[str, Any]]:
"""List documents in the knowledge base with optional pagination and filtering.
"""List documents in the knowledge base with optional pagination.
Args:
limit: Maximum number of documents to return.
offset: Number of documents to skip.
filter: Optional SQL WHERE clause to filter documents.
"""
from haiku.rag.client import HaikuRAG
async with HaikuRAG(db_path, config=config, read_only=True) as rag:
documents = await rag.list_documents(limit, offset, filter)
documents = await rag.list_documents(limit, offset)
result = [
{
"id": doc.id,

View file

@ -5,7 +5,6 @@ from pydantic_ai import FunctionToolset, RunContext
from haiku.rag.config.models import AppConfig
from haiku.rag.store.models import SearchResult
from haiku.rag.tools.context import RAGDeps
from haiku.rag.tools.filters import combine_filters
def create_search_toolset(
@ -35,21 +34,19 @@ def create_search_toolset(
ctx: RunContext[RAGDeps],
query: str,
limit: int | None = None,
filter: str | None = None,
) -> str:
"""Search the knowledge base for relevant documents.
Args:
query: The search query (what to search for).
limit: Number of results to return (default: from config).
filter: Optional SQL WHERE clause to filter documents.
Returns:
Formatted search results with content and metadata.
"""
client = ctx.deps.client
effective_filter = combine_filters(base_filter, filter)
effective_filter = base_filter
effective_limit = limit or config.search.limit
results = await client.search(
query, limit=effective_limit, filter=effective_filter

View file

@ -67,19 +67,6 @@ class TestSearchToolExecution:
assert result == "No results found."
@pytest.mark.asyncio
async def test_search_with_filter(self, search_client, search_config):
"""Search tool respects filter parameter."""
accumulated: list[SearchResult] = []
toolset = create_search_toolset(search_config, on_results=accumulated.extend)
search_tool = toolset.tools["search"]
ctx = make_ctx(search_client)
await search_tool.function(ctx, "programming", filter="title LIKE '%Python%'")
for r in accumulated:
assert "JavaScript" not in (r.document_title or "")
@pytest.mark.asyncio
async def test_search_with_base_filter(self, search_client, search_config):
"""Search toolset respects base_filter parameter."""