From 273a3bda4f7899c73ebddb86ab2018b54b633cba Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Sat, 28 Jun 2025 09:37:59 +0300 Subject: [PATCH] Document QA --- README.md | 8 ++++++++ docs/cli.md | 9 +++++++++ docs/configuration.md | 47 +++++++++++++++++++++++++++++++++++++++++++ docs/index.md | 6 ++++++ docs/python.md | 15 ++++++++++++++ 5 files changed, 85 insertions(+) diff --git a/README.md b/README.md index 8e20b3e1..cf86ae99 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Retrieval-Augmented Generation (RAG) library on SQLite. - **Local SQLite**: No external servers required - **Multiple embedding providers**: Ollama, VoyageAI, OpenAI - **Hybrid search**: Vector + full-text search with Reciprocal Rank Fusion +- **Question answering**: Built-in QA agents on your documents - **File monitoring**: Auto-index files when run as server - **40+ file formats**: PDF, DOCX, HTML, Markdown, audio, URLs - **MCP server**: Expose as tools for AI assistants @@ -27,6 +28,9 @@ haiku-rag add-src document.pdf # Search haiku-rag search "query" +# Ask questions +haiku-rag ask "Who is the author of haiku.rag?" + # Start server with file monitoring export MONITOR_DIRECTORIES="/path/to/docs" haiku-rag serve @@ -45,6 +49,10 @@ async with HaikuRAG("database.db") as client: results = await client.search("query") for chunk, score in results: print(f"{score:.3f}: {chunk.content}") + + # Ask questions + answer = await client.ask("Who is the author of haiku.rag?") + print(answer) ``` ## MCP Server diff --git a/docs/cli.md b/docs/cli.md index e5100062..fae3db8a 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -47,6 +47,15 @@ With options: haiku-rag search "python programming" --limit 10 --k 100 ``` +## Question Answering + +Ask questions about your documents: +```bash +haiku-rag ask "Who is the author of haiku.rag?" +``` + +The QA agent will search your documents for relevant information and provide a comprehensive answer. + ## Server Start the MCP server: diff --git a/docs/configuration.md b/docs/configuration.md index 8ba6cc7e..cae8a1dd 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -55,3 +55,50 @@ EMBEDDINGS_MODEL="text-embedding-3-small" # or text-embedding-3-large EMBEDDINGS_VECTOR_DIM=1536 OPENAI_API_KEY="your-api-key" ``` + +## Question Answering Providers + +Configure which LLM provider to use for question answering. + +### Ollama (Default) + +```bash +QA_PROVIDER="ollama" +QA_MODEL="qwen3" +OLLAMA_BASE_URL="http://localhost:11434" +``` + +### OpenAI + +For OpenAI QA, you need to install haiku.rag with OpenAI extras: + +```bash +uv pip install haiku.rag --extra openai +``` + +Then configure: + +```bash +QA_PROVIDER="openai" +QA_MODEL="gpt-4o-mini" # or gpt-4, gpt-3.5-turbo, etc. +OPENAI_API_KEY="your-api-key" +``` + +## Other Settings + +### Database and Storage + +```bash +# Default data directory (where SQLite database is stored) +DEFAULT_DATA_DIR="/path/to/data" +``` + +### Document Processing + +```bash +# Chunk size for document processing +CHUNK_SIZE=256 + +# Chunk overlap for better context +CHUNK_OVERLAP=32 +``` diff --git a/docs/index.md b/docs/index.md index 404ae8b4..66117c63 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,6 +8,7 @@ - **Local SQLite**: No need to run additional servers - **Support for various embedding providers**: Ollama, VoyageAI, OpenAI or add your own - **Hybrid Search**: Vector search using `sqlite-vec` combined with full-text search `FTS5`, using Reciprocal Rank Fusion +- **Question Answering**: Built-in QA agents using Ollama or OpenAI. - **File monitoring**: Automatically index files when run as a server - **Extended file format support**: Parse 40+ file formats including PDF, DOCX, HTML, Markdown, audio and more. Or add a URL! - **MCP server**: Exposes functionality as MCP tools @@ -31,12 +32,16 @@ async with HaikuRAG("database.db") as client: # Search documents results = await client.search("query") + + # Ask questions + answer = await client.ask("Who is the author of haiku.rag?") ``` Or use the CLI: ```bash haiku-rag add "Your document content" haiku-rag search "query" +haiku-rag ask "Who is the author of haiku.rag?" ``` ## Documentation @@ -44,6 +49,7 @@ haiku-rag search "query" - [Installation](installation.md) - Install haiku.rag with different providers - [Configuration](configuration.md) - Environment variables and settings - [CLI](cli.md) - Command line interface usage +- [Question Answering](qa.md) - QA agents and natural language queries - [Server](server.md) - File monitoring and server mode - [MCP](mcp.md) - Model Context Protocol integration - [Python](python.md) - Python API reference diff --git a/docs/python.md b/docs/python.md index 9908210e..ebc87f4c 100644 --- a/docs/python.md +++ b/docs/python.md @@ -91,4 +91,19 @@ for chunk, relevance_score in results: print(f"Relevance: {relevance_score:.3f}") print(f"Content: {chunk.content}") print(f"From document: {chunk.document_id}") + print(f"Document URI: {chunk.document_uri}") + print(f"Document metadata: {chunk.document_meta}") ``` + +## Question Answering + +Ask questions about your documents: + +```python +answer = await client.ask("Who is the author of haiku.rag?") +print(answer) +``` + +The QA agent will search your documents for relevant information and use the configured LLM to generate a comprehensive answer. + +The QA provider and model can be configured via environment variables (see [Configuration](configuration.md)).