Test count_documents

This commit is contained in:
Yiorgis Gozadinos 2026-01-27 17:17:05 +02:00
parent 626f5cdd0e
commit 5bfd6db984
No known key found for this signature in database
2 changed files with 26 additions and 1 deletions

View file

@ -4,7 +4,7 @@
### Added
- **Chat Agent Document Awareness Tools**: Two new tools for browsing and understanding the knowledge base
- `list_documents`Browse available documents with title, URI, and creation date; respects session document filter; paginated with total count
- `list_documents`Returns `DocumentListResponse` with paginated documents (50 per page), page number, total pages, and total count; respects session document filter
- `summarize_document` — Generate LLM-powered summaries of specific documents
- **Document Count API**: New `count_documents(filter)` method on `HaikuRAG` client for efficient document counting
- **Read-Only Initial Context**: Initial context is now locked after the first message, providing consistent session context

View file

@ -1137,6 +1137,31 @@ async def test_summarize_document_not_found(allow_model_requests, temp_db_path):
# Should indicate the document wasn't found
# =============================================================================
# count_documents Tests
# =============================================================================
@pytest.mark.asyncio
async def test_count_documents(temp_db_path):
"""Test count_documents method."""
async with HaikuRAG(temp_db_path, create=True) as client:
# Empty database
assert await client.count_documents() == 0
# Add documents
await client.create_document(content="Doc 1", uri="test/doc1.pdf")
await client.create_document(content="Doc 2", uri="test/doc2.pdf")
await client.create_document(content="Doc 3", uri="other/doc3.txt")
# Count all
assert await client.count_documents() == 3
# Count with filter
assert await client.count_documents(filter="uri LIKE '%.pdf'") == 2
assert await client.count_documents(filter="uri LIKE '%.txt'") == 1
def test_citation_index_fallback_without_session_state():
"""Test that citation indices fall back to sequential numbering without session_state.