Merge pull request #292 from ggozad/fix/fix-filter
Remove filter parameter from search and list_documents tools
This commit is contained in:
commit
a9583abd76
4 changed files with 7 additions and 21 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
## [Unreleased]
|
## [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
|
## [0.32.2] - 2026-02-28
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
||||||
|
|
@ -140,19 +140,17 @@ def create_skill(
|
||||||
ctx: RunContext[SkillRunDeps],
|
ctx: RunContext[SkillRunDeps],
|
||||||
limit: int | None = None,
|
limit: int | None = None,
|
||||||
offset: int | None = None,
|
offset: int | None = None,
|
||||||
filter: str | None = None,
|
|
||||||
) -> list[dict[str, Any]]:
|
) -> 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:
|
Args:
|
||||||
limit: Maximum number of documents to return.
|
limit: Maximum number of documents to return.
|
||||||
offset: Number of documents to skip.
|
offset: Number of documents to skip.
|
||||||
filter: Optional SQL WHERE clause to filter documents.
|
|
||||||
"""
|
"""
|
||||||
from haiku.rag.client import HaikuRAG
|
from haiku.rag.client import HaikuRAG
|
||||||
|
|
||||||
async with HaikuRAG(db_path, config=config, read_only=True) as rag:
|
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 = [
|
result = [
|
||||||
{
|
{
|
||||||
"id": doc.id,
|
"id": doc.id,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ from pydantic_ai import FunctionToolset, RunContext
|
||||||
from haiku.rag.config.models import AppConfig
|
from haiku.rag.config.models import AppConfig
|
||||||
from haiku.rag.store.models import SearchResult
|
from haiku.rag.store.models import SearchResult
|
||||||
from haiku.rag.tools.context import RAGDeps
|
from haiku.rag.tools.context import RAGDeps
|
||||||
from haiku.rag.tools.filters import combine_filters
|
|
||||||
|
|
||||||
|
|
||||||
def create_search_toolset(
|
def create_search_toolset(
|
||||||
|
|
@ -35,21 +34,19 @@ def create_search_toolset(
|
||||||
ctx: RunContext[RAGDeps],
|
ctx: RunContext[RAGDeps],
|
||||||
query: str,
|
query: str,
|
||||||
limit: int | None = None,
|
limit: int | None = None,
|
||||||
filter: str | None = None,
|
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Search the knowledge base for relevant documents.
|
"""Search the knowledge base for relevant documents.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
query: The search query (what to search for).
|
query: The search query (what to search for).
|
||||||
limit: Number of results to return (default: from config).
|
limit: Number of results to return (default: from config).
|
||||||
filter: Optional SQL WHERE clause to filter documents.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Formatted search results with content and metadata.
|
Formatted search results with content and metadata.
|
||||||
"""
|
"""
|
||||||
client = ctx.deps.client
|
client = ctx.deps.client
|
||||||
|
|
||||||
effective_filter = combine_filters(base_filter, filter)
|
effective_filter = base_filter
|
||||||
effective_limit = limit or config.search.limit
|
effective_limit = limit or config.search.limit
|
||||||
results = await client.search(
|
results = await client.search(
|
||||||
query, limit=effective_limit, filter=effective_filter
|
query, limit=effective_limit, filter=effective_filter
|
||||||
|
|
|
||||||
|
|
@ -67,19 +67,6 @@ class TestSearchToolExecution:
|
||||||
|
|
||||||
assert result == "No results found."
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_search_with_base_filter(self, search_client, search_config):
|
async def test_search_with_base_filter(self, search_client, search_config):
|
||||||
"""Search toolset respects base_filter parameter."""
|
"""Search toolset respects base_filter parameter."""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue