Document QA
This commit is contained in:
parent
4bbc23dbd4
commit
273a3bda4f
5 changed files with 85 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)).
|
||||
|
|
|
|||
Loading…
Reference in a new issue