diff --git a/CHANGELOG.md b/CHANGELOG.md index 21b38a42..3324ebbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - **S3/Object storage support**: Connect to LanceDB on S3, GCS, Azure Blob, or HDFS via `lancedb.uri` and `storage_options` config. Supports S3-compatible stores with custom endpoints. - **Remote skill generation**: `create-skill` now supports remote databases — omit `--db` and provide `--config-file` to generate skills that connect to object storage at runtime instead of bundling the database. +### Fixed + +- **Skill `list_documents` ignores `document_filter`**: `list_documents` tool now respects `state.document_filter`, consistent with `search`, `ask`, and `research` + ## [0.38.0] - 2026-04-07 ### Added diff --git a/docs/skills/rag.md b/docs/skills/rag.md index e9d38a1a..def50f98 100644 --- a/docs/skills/rag.md +++ b/docs/skills/rag.md @@ -41,7 +41,7 @@ class RAGState(BaseModel): - **citations** — Accumulated citations from `ask` calls, with sequential indexing across calls. - **qa_history** — Questions and answers from `ask` calls. Prior Q&A is used as context for follow-up questions when embeddings are similar. -- **document_filter** — SQL WHERE clause applied to `search`, `ask`, and `research` calls. Set this to scope queries to specific documents. +- **document_filter** — SQL WHERE clause applied to `search`, `list_documents`, `ask`, and `research` calls. Set this to scope queries to specific documents. - **searches** — Search results keyed by query string. - **documents** — Documents seen via `list_documents` or `get_document` (deduplicated by ID). - **reports** — Research reports from `research` calls. diff --git a/haiku_rag_slim/haiku/rag/skills/_tools.py b/haiku_rag_slim/haiku/rag/skills/_tools.py index dc64ff21..abefcc5e 100644 --- a/haiku_rag_slim/haiku/rag/skills/_tools.py +++ b/haiku_rag_slim/haiku/rag/skills/_tools.py @@ -90,11 +90,12 @@ async def skill_list_documents( config: AppConfig, limit: int | None = None, offset: int | None = None, + filter: str | None = None, ) -> list[dict[str, Any]]: 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) + documents = await rag.list_documents(limit, offset, filter=filter) return [ { "id": doc.id, @@ -350,8 +351,14 @@ def create_skill_tools( limit: Maximum number of documents to return. offset: Number of documents to skip. """ - result = await skill_list_documents(db_path, config, limit, offset) state = _get_state(ctx, state_type) + result = await skill_list_documents( + db_path, + config, + limit, + offset, + filter=state.document_filter if state else None, + ) if state: update_documents_state(state.documents, result) return result diff --git a/tests/skills/test_rag.py b/tests/skills/test_rag.py index 546425fc..85ea7448 100644 --- a/tests/skills/test_rag.py +++ b/tests/skills/test_rag.py @@ -276,6 +276,17 @@ class TestListDocumentsTool: assert isinstance(state.documents[0], DocumentInfo) assert state.documents[0].id is not None + async def test_list_documents_applies_document_filter_from_state(self, rag_db): + from haiku.rag.skills.rag import RAGState, create_skill + + skill = create_skill(db_path=rag_db) + list_docs = _get_tool(skill, "list_documents") + state = RAGState(document_filter="title = 'AI Overview'") + ctx = _make_ctx(state) + results = await list_docs(ctx) + assert len(results) == 1 + assert results[0]["title"] == "AI Overview" + async def test_list_documents_no_duplicates_in_state(self, rag_db): from haiku.rag.skills.rag import RAGState, create_skill