diff --git a/README.md b/README.md index da0f2dff..c2ab5903 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ haiku-rag add-src document.pdf --meta source=manual # Search haiku-rag search "query" +# Search with filters +haiku-rag search "query" --filter "uri LIKE '%.pdf' AND title LIKE '%paper%'" + # Ask questions haiku-rag ask "Who is the author of haiku.rag?" diff --git a/docs/cli.md b/docs/cli.md index 2b2e88ec..bddfdf31 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -78,6 +78,18 @@ With options: haiku-rag search "python programming" --limit 10 ``` +With filters (filter by document properties): +```bash +# Filter by URI pattern +haiku-rag search "neural networks" --filter "uri LIKE '%arxiv%'" + +# Filter by exact title +haiku-rag search "transformers" --filter "title = 'Deep Learning Guide'" + +# Combine multiple conditions +haiku-rag search "AI" --filter "uri LIKE '%.pdf' AND title LIKE '%paper%'" +``` + ## Question Answering Ask questions about your documents: diff --git a/docs/python.md b/docs/python.md index d462b625..3bd93d00 100644 --- a/docs/python.md +++ b/docs/python.md @@ -168,6 +168,48 @@ for chunk, relevance_score in results: print(f"Document metadata: {chunk.document_meta}") ``` +### Filtering Search Results + +Filter search results to only include chunks from documents matching specific criteria: + +```python +# Filter by document URI pattern +results = await client.search( + query="machine learning", + limit=5, + filter="uri LIKE '%arxiv%'" +) + +# Filter by exact document title +results = await client.search( + query="neural networks", + limit=5, + filter="title = 'Deep Learning Guide'" +) + +# Combine multiple filter conditions +results = await client.search( + query="AI research", + limit=5, + filter="uri LIKE '%.pdf' AND title LIKE '%paper%'" +) + +# Filter with any search type +results = await client.search( + query="transformers", + limit=5, + search_type="vector", + filter="uri LIKE '%huggingface%'" +) +``` + +**Note:** Filters apply to document properties only. Available columns for filtering: +- `id` - Document ID +- `uri` - Document URI/URL +- `title` - Document title (if set) +- `created_at`, `updated_at` - Timestamps +- `metadata` - Document metadata (as string, use LIKE for pattern matching) + ### Expanding Search Context Expand search results with adjacent chunks for more complete context: