Merge pull request #130 from ggozad/chore/uv-workspace
Introduce haiku.rag-slim with minimal dependencies. haiku.rag gets all optionals installed.
This commit is contained in:
commit
e6a701ebb6
104 changed files with 723 additions and 383 deletions
|
|
@ -60,7 +60,7 @@ tests/
|
|||
.pytest_cache/
|
||||
.coverage
|
||||
htmlcov/
|
||||
src/evaluations/
|
||||
evaluations/evaluations/data/
|
||||
server.json
|
||||
# Examples
|
||||
examples/
|
||||
|
|
|
|||
18
.github/workflows/build-publish-slim.yml
vendored
Normal file
18
.github/workflows/build-publish-slim.yml
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
name: Build & publish haiku.rag-slim to pypi
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up uv
|
||||
run: curl -LsSf https://astral.sh/uv/0.3.0/install.sh | sh
|
||||
- name: Set up Python 3.12
|
||||
run: uv python install 3.12
|
||||
- name: Build haiku.rag-slim
|
||||
run: uv build --package haiku.rag-slim
|
||||
- name: Publish haiku.rag-slim
|
||||
run: uvx twine upload -u __token__ -p ${{ secrets.PYPI_API_TOKEN }} dist/* --non-interactive
|
||||
20
.github/workflows/build-publish.yml
vendored
20
.github/workflows/build-publish.yml
vendored
|
|
@ -1,18 +1,22 @@
|
|||
name: Build & publish to pypi
|
||||
name: Build & publish haiku.rag to pypi
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_run:
|
||||
workflows: ["Build & publish haiku.rag-slim to pypi"]
|
||||
types:
|
||||
- completed
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up uv
|
||||
run: curl -LsSf https://astral.sh/uv/0.3.0/install.sh | sh
|
||||
- name: Set up Python 3.10
|
||||
run: uv python install 3.10
|
||||
- name: Build package
|
||||
run: uvx --from build pyproject-build --installer uv
|
||||
- name: Publish package
|
||||
- name: Set up Python 3.12
|
||||
run: uv python install 3.12
|
||||
- name: Build haiku.rag
|
||||
run: uv build
|
||||
- name: Publish haiku.rag
|
||||
run: uvx twine upload -u __token__ -p ${{ secrets.PYPI_API_TOKEN }} dist/* --non-interactive
|
||||
|
|
|
|||
4
.github/workflows/docker-publish.yml
vendored
4
.github/workflows/docker-publish.yml
vendored
|
|
@ -1,7 +1,7 @@
|
|||
name: Build & publish Docker image
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Build & publish to pypi"]
|
||||
workflows: ["Build & publish haiku.rag to pypi"]
|
||||
types:
|
||||
- completed
|
||||
workflow_dispatch:
|
||||
|
|
@ -40,7 +40,7 @@ jobs:
|
|||
- name: Extract version from pyproject.toml
|
||||
id: version
|
||||
run: |
|
||||
VERSION=$(grep -oP '^version = "\K[^"]+' pyproject.toml)
|
||||
VERSION=$(grep -oP '^version = "\K[^"]+' haiku_rag_slim/pyproject.toml)
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and push Docker image
|
||||
|
|
|
|||
4
.github/workflows/publish-mcp.yml
vendored
4
.github/workflows/publish-mcp.yml
vendored
|
|
@ -2,7 +2,7 @@ name: Publish to MCP Registry
|
|||
on:
|
||||
workflow_dispatch:
|
||||
workflow_run:
|
||||
workflows: ["Build & publish to pypi"]
|
||||
workflows: ["Build & publish haiku.rag to pypi"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ jobs:
|
|||
python-version: '3.12'
|
||||
- name: Generate server.json from template
|
||||
run: |
|
||||
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
|
||||
VERSION=$(python -c "import tomllib; print(tomllib.load(open('haiku_rag_slim/pyproject.toml', 'rb'))['project']['version'])")
|
||||
sed "s/{{VERSION}}/$VERSION/g" server.json > server.json.tmp
|
||||
mv server.json.tmp server.json
|
||||
echo "Generated server.json with version: $VERSION"
|
||||
|
|
|
|||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -11,7 +11,7 @@ wheels/
|
|||
|
||||
# tests
|
||||
.coverage*
|
||||
src/evaluations/data/
|
||||
evaluations/evaluations/data/
|
||||
tests/data/
|
||||
.pytest_cache/
|
||||
.ruff_cache/
|
||||
|
|
|
|||
69
CHANGELOG.md
Normal file
69
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# Changelog
|
||||
## [Unreleased]
|
||||
|
||||
## [0.14.0] - 2024-11-05
|
||||
|
||||
### Added
|
||||
|
||||
- New `haiku.rag-slim` package with minimal dependencies for users who want to install only what they need
|
||||
- Evaluations package (`haiku.rag-evals`) for internal benchmarking and testing
|
||||
- Improved search filtering performance by using pandas DataFrames for joins instead of SQL WHERE IN clauses
|
||||
|
||||
### Changed
|
||||
|
||||
- **BREAKING**: Restructured project into UV workspace with three packages:
|
||||
- `haiku.rag-slim` - Core package with minimal dependencies
|
||||
- `haiku.rag` - Full package with all extras (recommended for most users)
|
||||
- `haiku.rag-evals` - Internal benchmarking and evaluation tools
|
||||
- Migrated from `pydantic-ai` to `pydantic-ai-slim` with extras system
|
||||
- Docling is now an optional dependency (install with `haiku.rag-slim[docling]`)
|
||||
- Package metadata checks now use `haiku.rag-slim` (always present) instead of `haiku.rag`
|
||||
- Docker image optimized: removed evaluations package, reducing installed packages from 307 to 259
|
||||
- Improved vector search performance through optimized score normalization
|
||||
|
||||
### Fixed
|
||||
|
||||
- ImportError now properly raised when optional docling dependency is missing
|
||||
|
||||
## [0.13.3] - 2024-11-04
|
||||
|
||||
### Added
|
||||
|
||||
- Support for Zero Entropy reranker
|
||||
- Filter parameter to `search()` for filtering documents before search
|
||||
- Filter parameter to CLI `search` command
|
||||
- Filter parameter to CLI `list` command for filtering document listings
|
||||
- Config option to pass custom configuration files to evaluation commands
|
||||
- Document filtering now respects configured include/exclude patterns when using `add-src` with directories
|
||||
- Max retries to insight_agent when producing structured output
|
||||
|
||||
### Fixed
|
||||
|
||||
- CLI now loads `.env` files at startup
|
||||
- Info command no longer attempts to use deprecated `.env` settings
|
||||
- Documentation typos
|
||||
|
||||
## [0.13.2] - 2024-11-04
|
||||
|
||||
### Added
|
||||
|
||||
- Gitignore-style pattern filtering for file monitoring using pathspec
|
||||
- Include/exclude pattern documentation for FileMonitor
|
||||
|
||||
### Changed
|
||||
|
||||
- Moved monitor configuration to its own section in config
|
||||
- Improved configuration documentation
|
||||
- Updated dependencies
|
||||
|
||||
## [0.13.1] - 2024-11-03
|
||||
|
||||
### Added
|
||||
|
||||
- Initial version tracking
|
||||
|
||||
[Unreleased]: https://github.com/ggozad/haiku.rag/compare/0.14.0...HEAD
|
||||
[0.14.0]: https://github.com/ggozad/haiku.rag/compare/0.13.3...0.14.0
|
||||
[0.13.3]: https://github.com/ggozad/haiku.rag/compare/0.13.2...0.13.3
|
||||
[0.13.2]: https://github.com/ggozad/haiku.rag/compare/0.13.1...0.13.2
|
||||
[0.13.1]: https://github.com/ggozad/haiku.rag/releases/tag/0.13.1
|
||||
28
README.md
28
README.md
|
|
@ -1,7 +1,5 @@
|
|||
# Haiku RAG
|
||||
|
||||
mcp-name: io.github.ggozad/haiku-rag
|
||||
|
||||
Retrieval-Augmented Generation (RAG) library built on LanceDB.
|
||||
|
||||
`haiku.rag` is a Retrieval-Augmented Generation (RAG) library built to work with LanceDB as a local vector database. It uses LanceDB for storing embeddings and performs semantic (vector) search as well as full-text search combined through native hybrid search with Reciprocal Rank Fusion. Both open-source (Ollama) as well as commercial (OpenAI, VoyageAI) embedding providers are supported.
|
||||
|
|
@ -23,13 +21,29 @@ Retrieval-Augmented Generation (RAG) library built on LanceDB.
|
|||
- **A2A agent**: Conversational agent with context and multi-turn dialogue
|
||||
- **CLI & Python API**: Use from command line or Python
|
||||
|
||||
## Installation
|
||||
|
||||
**Python 3.12 or newer required**
|
||||
|
||||
### Full Package (Recommended)
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag
|
||||
```
|
||||
|
||||
Includes all features: document processing, all embedding providers, rerankers, and A2A agent support.
|
||||
|
||||
### Slim Package (Minimal Dependencies)
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag-slim
|
||||
```
|
||||
|
||||
Install only the extras you need. See the [Installation](https://ggozad.github.io/haiku.rag/installation/) documentation for available options
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
# Install
|
||||
# Python 3.12 or newer required
|
||||
uv pip install haiku.rag
|
||||
|
||||
# Add documents
|
||||
haiku-rag add "Your content here"
|
||||
haiku-rag add "Your content here" --meta author=alice --meta topic=notes
|
||||
|
|
@ -187,3 +201,5 @@ Full documentation at: https://ggozad.github.io/haiku.rag/
|
|||
- [MCP Server](https://ggozad.github.io/haiku.rag/mcp/) - Model Context Protocol integration
|
||||
- [A2A Agent](https://ggozad.github.io/haiku.rag/a2a/) - Agent-to-Agent protocol support
|
||||
- [Benchmarks](https://ggozad.github.io/haiku.rag/benchmarks/) - Performance Benchmarks
|
||||
|
||||
mcp-name: io.github.ggozad/haiku-rag
|
||||
|
|
|
|||
|
|
@ -8,14 +8,18 @@ ENV UV_COMPILE_BYTECODE=1 \
|
|||
UV_LINK_MODE=copy
|
||||
|
||||
# Install dependencies into a venv
|
||||
# In workspace: root package (haiku.rag) includes all extras via haiku.rag-slim
|
||||
# Copy workspace member directories first (needed for workspace resolution)
|
||||
COPY pyproject.toml uv.lock ./
|
||||
COPY haiku_rag_slim/pyproject.toml haiku_rag_slim/README.md haiku_rag_slim/LICENSE haiku_rag_slim/
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
uv sync --frozen --no-install-project --extra voyageai --extra mxbai --extra a2a
|
||||
uv sync --frozen --no-install-project --no-dev
|
||||
|
||||
# Install the project itself
|
||||
COPY . .
|
||||
COPY haiku_rag_slim haiku_rag_slim/
|
||||
COPY README.md LICENSE ./
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
uv sync --frozen --no-editable --extra voyageai --extra mxbai --extra a2a
|
||||
uv sync --frozen --no-editable --no-dev
|
||||
|
||||
# Final layer
|
||||
FROM python:3.13-slim
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
We use the [repliqa](https://huggingface.co/datasets/ServiceNow/repliqa) dataset for the evaluation of `haiku.rag`.
|
||||
|
||||
You can perform your own evaluations with the Typer CLI in
|
||||
`src/evaluations/benchmark.py`, for example `cd src && python -m evaluations.benchmark repliqa`.
|
||||
`evaluations/evaluations/benchmark.py`, for example `python -m evaluations.benchmark repliqa`.
|
||||
The evaluation flow is orchestrated with
|
||||
[`pydantic-evals`](https://github.com/pydantic/pydantic-ai/tree/main/libs/pydantic-evals),
|
||||
which we leverage for dataset management, scoring, and report generation.
|
||||
|
|
@ -13,7 +13,7 @@ which we leverage for dataset management, scoring, and report generation.
|
|||
The benchmark script accepts a `--config` option to specify a custom `haiku.rag.yaml` configuration file:
|
||||
|
||||
```bash
|
||||
cd src && python -m evaluations.benchmark repliqa --config /path/to/haiku.rag.yaml
|
||||
python -m evaluations.benchmark repliqa --config /path/to/haiku.rag.yaml
|
||||
```
|
||||
|
||||
If no config file is specified, the script will search for a config file in the standard locations:
|
||||
|
|
|
|||
|
|
@ -238,10 +238,10 @@ If neither is set, it defaults to `http://localhost:11434`.
|
|||
|
||||
### VoyageAI
|
||||
|
||||
If you want to use VoyageAI embeddings you will need to install `haiku.rag` with the VoyageAI extras:
|
||||
If you installed `haiku.rag` (full package), VoyageAI is already included. If you installed `haiku.rag-slim`, install with VoyageAI extras:
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag[voyageai]
|
||||
uv pip install haiku.rag-slim[voyageai]
|
||||
```
|
||||
|
||||
```yaml
|
||||
|
|
@ -396,10 +396,10 @@ Reranking is **disabled by default** (`provider: ""`) for faster searches. You c
|
|||
|
||||
### MixedBread AI
|
||||
|
||||
For MxBAI reranking, install with mxbai extras:
|
||||
If you installed `haiku.rag` (full package), MxBAI is already included. If you installed `haiku.rag-slim`, add the mxbai extra:
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag[mxbai]
|
||||
uv pip install haiku.rag-slim[mxbai]
|
||||
```
|
||||
|
||||
Then configure:
|
||||
|
|
@ -412,10 +412,10 @@ reranking:
|
|||
|
||||
### Cohere
|
||||
|
||||
Install with cohere extras:
|
||||
If you installed `haiku.rag` (full package), Cohere is already included. If you installed `haiku.rag-slim`, add the cohere extra:
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag[cohere]
|
||||
uv pip install haiku.rag-slim[cohere]
|
||||
```
|
||||
|
||||
Then configure:
|
||||
|
|
@ -434,10 +434,10 @@ export CO_API_KEY=your-api-key
|
|||
|
||||
### Zero Entropy
|
||||
|
||||
Install with zeroentropy extras:
|
||||
If you installed `haiku.rag` (full package), Zero Entropy is already included. If you installed `haiku.rag-slim`, add the zeroentropy extra:
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag[zeroentropy]
|
||||
uv pip install haiku.rag-slim[zeroentropy]
|
||||
```
|
||||
|
||||
Then configure:
|
||||
|
|
|
|||
|
|
@ -1,97 +1,56 @@
|
|||
# Installation
|
||||
|
||||
## Basic Installation
|
||||
## Choose Your Package
|
||||
|
||||
**haiku.rag** is available in two packages:
|
||||
|
||||
### Full Package (Recommended)
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag
|
||||
```
|
||||
|
||||
This includes support for:
|
||||
- **Ollama** (default embedding provider using `mxbai-embed-large`)
|
||||
The full package includes **all features and extras**:
|
||||
- **Document processing** (Docling) - PDF, DOCX, PPTX, images, and 40+ file formats
|
||||
- **All embedding providers** - VoyageAI
|
||||
- **All rerankers** - MixedBread AI, Cohere, Zero Entropy
|
||||
- **A2A agent** - Agent-to-Agent protocol support
|
||||
|
||||
This is the easiest way to get started with all features enabled.
|
||||
|
||||
### Slim Package (Minimal Dependencies)
|
||||
|
||||
```bash
|
||||
# Minimal installation (no document processing)
|
||||
uv pip install haiku.rag-slim
|
||||
|
||||
# With document processing
|
||||
uv pip install haiku.rag-slim[docling]
|
||||
|
||||
# With specific providers
|
||||
uv pip install haiku.rag-slim[docling,voyageai,mxbai]
|
||||
```
|
||||
|
||||
The slim package has minimal dependencies and lets you install only what you need:
|
||||
|
||||
- `docling` - PDF, DOCX, PPTX, images, and other document formats
|
||||
- `voyageai` - VoyageAI embeddings
|
||||
- `mxbai` - MixedBread AI reranking
|
||||
- `a2a` - Agent-to-Agent protocol support
|
||||
- `cohere` - Cohere reranking
|
||||
- `zeroentropy` - Zero Entropy reranking
|
||||
|
||||
**Built-in providers** (no extras needed):
|
||||
- **Ollama** (default embedding provider)
|
||||
- **OpenAI** (GPT models for QA and embeddings)
|
||||
- **Anthropic** (Claude models for QA)
|
||||
- **vLLM** (high-performance local inference for embeddings, QA, and reranking)
|
||||
|
||||
## Provider-Specific Installation
|
||||
|
||||
For additional providers, install with extras:
|
||||
|
||||
### Embedding Providers
|
||||
|
||||
#### VoyageAI
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag[voyageai]
|
||||
```
|
||||
|
||||
### Reranking Providers
|
||||
|
||||
#### MixedBread AI
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag[mxbai]
|
||||
```
|
||||
|
||||
#### Cohere
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag[cohere]
|
||||
```
|
||||
|
||||
#### Zero Entropy
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag[zeroentropy]
|
||||
```
|
||||
|
||||
### vLLM Setup
|
||||
|
||||
vLLM requires no additional installation - it works with the base haiku.rag package. However, you need to run vLLM servers separately:
|
||||
|
||||
```bash
|
||||
# Install vLLM
|
||||
pip install vllm
|
||||
|
||||
# Serve an embedding model
|
||||
vllm serve mixedbread-ai/mxbai-embed-large-v1 --port 8000
|
||||
|
||||
# Serve a model for QA (requires tool calling support)
|
||||
vllm serve Qwen/Qwen3-4B --port 8002 --enable-auto-tool-choice --tool-call-parser hermes
|
||||
|
||||
# Serve a model for reranking
|
||||
vllm serve mixedbread-ai/mxbai-rerank-base-v2 --hf_overrides '{"architectures": ["Qwen2ForSequenceClassification"],"classifier_from_token": ["0", "1"], "method": "from_2_way_softmax"}' --port 8001
|
||||
```
|
||||
|
||||
Then configure haiku.rag to use the vLLM servers. Create a `haiku.rag.yaml` file:
|
||||
|
||||
```yaml
|
||||
embeddings:
|
||||
provider: vllm
|
||||
model: mixedbread-ai/mxbai-embed-large-v1
|
||||
vector_dim: 512
|
||||
|
||||
qa:
|
||||
provider: vllm
|
||||
model: Qwen/Qwen3-4B
|
||||
|
||||
reranking:
|
||||
provider: vllm
|
||||
model: mixedbread-ai/mxbai-rerank-base-v2
|
||||
|
||||
providers:
|
||||
vllm:
|
||||
embeddings_base_url: http://localhost:8000
|
||||
qa_base_url: http://localhost:8002
|
||||
rerank_base_url: http://localhost:8001
|
||||
```
|
||||
|
||||
See [Configuration](configuration.md) for all available options.
|
||||
See [Configuration](configuration.md) for configuring providers including advanced options like vLLM.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Python 3.12+
|
||||
- Ollama (for default embeddings)
|
||||
- vLLM server (for vLLM provider)
|
||||
- Ollama (for default embeddings and QA)
|
||||
|
||||
## Pre-download Models (Optional)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
# Tutorial
|
||||
|
||||
This tutorial quickstart instructions for getting familiar with `haiku.rag`. This tutorial is intended for people who are familiar with command line and Python, but not different AI ecosystem tools.
|
||||
This tutorial provides quickstart instructions for getting familiar with `haiku.rag`. This tutorial is intended for people who are familiar with command line and Python, but not different AI ecosystem tools.
|
||||
|
||||
The tutorial covers:
|
||||
|
||||
- RAG and embeddings basics
|
||||
- Install `haiku.rag` Python package
|
||||
- Set up environment variables for running `haiku.rag`
|
||||
- Installing `haiku.rag` Python package
|
||||
- Configuring `haiku.rag` with YAML
|
||||
- Adding and retrieving items
|
||||
- Inspecting the database
|
||||
|
||||
|
|
@ -14,11 +14,9 @@ The tutorial uses OpenAI API service - no local installation needed and will wor
|
|||
|
||||
## Introduction
|
||||
|
||||
Embeddings serve as the foundational bridge between unstructured text data and computational efficiency in AI systems, particularly within Retrieval-Augmented Generation (RAG) frameworks that enhance Large Language Models (LLMs). At their core, embeddings are dense vector representations of words, sentences, or documents, created by models like those from OpenAI, which encode semantic and contextual meaning into numerical forms. In a RAG pipeline, these embeddings enable the system to index and store vast amounts of information in a vector database, allowing for rapid similarity searches. When a user query is posed, its embedding is generated and compared against the stored vectors using metrics like cosine similarity to retrieve the most relevant documents or chunks of text. This retrieval step addresses a key limitation of standalone LLMs, which rely on pre-trained knowledge that can be outdated, incomplete, or prone to hallucinations, by providing external, grounded context to inform the model's output.
|
||||
Retrieval-Augmented Generation (RAG) lets you give AI models access to your own documents and data. Instead of relying solely on the model's training data, RAG finds relevant information from your documents and includes it in the AI's responses.
|
||||
|
||||
You technically can create vector embeddings yourself without relying on pre-built models like OpenAI's, but it's impractical for most users due to the complexity and resources involved in training or implementing from scratch. Generating embeddings requires a neural network architecture (e.g., transformer-based) trained on massive datasets to learn semantic relationships, which demands significant computational power (GPUs/TPUs), expertise in machine learning, and access to billions of text examples for fine-tuning.
|
||||
|
||||
`haiku.rag` is a Python library allowing you to set up your own embeddings database, pipeline to feed into it and query it with different LLM providers and related services.
|
||||
`haiku.rag` handles the mechanics: it converts your documents into searchable embeddings, stores them locally, and retrieves relevant chunks when you ask questions. You provide the documents and questions, and it coordinates between the embedding service (like OpenAI) and the AI model to give you accurate, grounded answers.
|
||||
|
||||
## Setup
|
||||
|
||||
|
|
@ -81,16 +79,16 @@ You should get the back the information:
|
|||
```
|
||||
haiku.rag database info
|
||||
path: /Users/moo/Library/Application Support/haiku.rag/haiku.rag.lancedb
|
||||
haiku.rag version (db): 0.12.1
|
||||
haiku.rag version (db): 0.13.3
|
||||
embeddings: openai/text-embedding-3-small (dim: 1536)
|
||||
documents: 4
|
||||
versions (documents): 9
|
||||
versions (chunks): 10
|
||||
documents: 3
|
||||
versions (documents): 3
|
||||
versions (chunks): 3
|
||||
──────────────────────────────────────────────────────────────────────────────────
|
||||
Versions
|
||||
haiku.rag: 0.12.1
|
||||
haiku.rag: 0.13.3
|
||||
lancedb: 0.25.2
|
||||
docling: 2.57.0
|
||||
docling: 2.58.0
|
||||
```
|
||||
|
||||
## Asking questions and retrieving information
|
||||
|
|
@ -167,7 +165,7 @@ According to the document, Python is considered the best programming language in
|
|||
|
||||
## Complex documents
|
||||
|
||||
Haiku RAG can also handle types beyond plain text.
|
||||
Haiku RAG can also handle types beyond plain text, including PDF, DOCX, HTML, and 40+ other file formats.
|
||||
|
||||
Here we add research papers about Python from [arxiv](https://arxiv.org/search/?query=python&searchtype=all&source=header) using URL retriever.
|
||||
|
||||
|
|
@ -215,14 +213,6 @@ The following people are presenting talks at PyCon Finland 2025:
|
|||
5 Andreas Jung (also presenting another talk) - Talk: Debugging Python
|
||||
```
|
||||
|
||||
## Reseting the embeddings database
|
||||
|
||||
If you change your embeddings provider (OpenAI -> ollama) or its parameters, you need to delete the LanceDB database and add the documents again:
|
||||
|
||||
```shell
|
||||
rm -rf "/Users/moo/Library/Application Support/haiku.rag/haiku.rag.lancedb"
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
See [Configuration page](./configuration.md) for complete documentation on YAML configuration and all available options.
|
||||
|
|
|
|||
7
evaluations/LICENSE
Normal file
7
evaluations/LICENSE
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Copyright 2025 Yiorgis Gozadinos
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
11
evaluations/README.md
Normal file
11
evaluations/README.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Haiku RAG - Evaluations
|
||||
|
||||
Internal benchmarking and evaluation scripts for haiku.rag.
|
||||
|
||||
This package is not published to PyPI and is only used for development and testing purposes.
|
||||
|
||||
## Overview
|
||||
|
||||
Contains evaluation scripts for benchmarking RAG performance using datasets like:
|
||||
- RepliQA
|
||||
- WiX
|
||||
|
|
@ -5,6 +5,10 @@ from typing import Any, cast
|
|||
|
||||
import logfire
|
||||
import typer
|
||||
from haiku.rag.client import HaikuRAG
|
||||
from haiku.rag.config import AppConfig, find_config_file, load_yaml_config
|
||||
from haiku.rag.logging import configure_cli_logging
|
||||
from haiku.rag.qa import get_qa_agent
|
||||
from pydantic_ai.models.openai import OpenAIChatModel
|
||||
from pydantic_ai.providers.ollama import OllamaProvider
|
||||
from pydantic_evals import Dataset as EvalDataset
|
||||
|
|
@ -17,10 +21,6 @@ from evaluations.config import DatasetSpec
|
|||
from evaluations.datasets import DATASETS
|
||||
from evaluations.llm_judge import ANSWER_EQUIVALENCE_RUBRIC
|
||||
from evaluations.prompts import WIX_SUPPORT_PROMPT
|
||||
from haiku.rag.client import HaikuRAG
|
||||
from haiku.rag.config import AppConfig, find_config_file, load_yaml_config
|
||||
from haiku.rag.logging import configure_cli_logging
|
||||
from haiku.rag.qa import get_qa_agent
|
||||
|
||||
QA_JUDGE_MODEL = "qwen3"
|
||||
|
||||
22
evaluations/pyproject.toml
Normal file
22
evaluations/pyproject.toml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
[project]
|
||||
|
||||
name = "haiku.rag-evals"
|
||||
description = "Internal benchmarking and evaluation scripts for haiku.rag"
|
||||
version = "0.14.0"
|
||||
authors = [{ name = "Yiorgis Gozadinos", email = "ggozadinos@gmail.com" }]
|
||||
license = { text = "MIT" }
|
||||
requires-python = ">=3.12"
|
||||
|
||||
dependencies = [
|
||||
"haiku.rag-slim",
|
||||
"pydantic-ai-slim[evals,logfire]>=1.11.0",
|
||||
"datasets>=4.3.0",
|
||||
"typer>=0.19.2,<0.20.0",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["evaluations"]
|
||||
7
haiku_rag_slim/LICENSE
Normal file
7
haiku_rag_slim/LICENSE
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Copyright 2025 Yiorgis Gozadinos
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
76
haiku_rag_slim/README.md
Normal file
76
haiku_rag_slim/README.md
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# haiku.rag-slim
|
||||
|
||||
Retrieval-Augmented Generation (RAG) library built on LanceDB - Core package with minimal dependencies.
|
||||
|
||||
`haiku.rag-slim` is the core package for users who want to install only the dependencies they need. Document processing (docling), rerankers, and A2A support are all optional extras.
|
||||
|
||||
**For most users, we recommend installing [`haiku.rag`](https://pypi.org/project/haiku.rag/) instead**, which includes all features out of the box.
|
||||
|
||||
## Installation
|
||||
|
||||
**Python 3.12 or newer required**
|
||||
|
||||
### Minimal Installation
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag-slim
|
||||
```
|
||||
|
||||
Core functionality with OpenAI/Ollama support, MCP server, and Logfire observability. Document processing (docling) is optional.
|
||||
|
||||
### With Document Processing
|
||||
|
||||
```bash
|
||||
uv pip install haiku.rag-slim[docling]
|
||||
```
|
||||
|
||||
Adds support for 40+ file formats including PDF, DOCX, HTML, and more.
|
||||
|
||||
### Available Extras
|
||||
|
||||
**Document Processing:**
|
||||
- `docling` - PDF, DOCX, HTML, and 40+ file formats
|
||||
|
||||
**Embedding Providers:**
|
||||
- `voyageai` - VoyageAI embeddings
|
||||
|
||||
**Rerankers:**
|
||||
- `mxbai` - MixedBread AI
|
||||
- `cohere` - Cohere
|
||||
- `zeroentropy` - Zero Entropy
|
||||
|
||||
**Model Providers:**
|
||||
- OpenAI/Ollama - included in core (OpenAI-compatible APIs)
|
||||
- `anthropic` - Anthropic Claude
|
||||
- `groq` - Groq
|
||||
- `google` - Google Gemini
|
||||
- `mistral` - Mistral AI
|
||||
- `bedrock` - AWS Bedrock
|
||||
- `vertexai` - Google Vertex AI
|
||||
|
||||
**Agent Protocol:**
|
||||
- `a2a` - Agent-to-Agent protocol
|
||||
|
||||
```bash
|
||||
# Common combinations
|
||||
uv pip install haiku.rag-slim[docling,anthropic,mxbai]
|
||||
uv pip install haiku.rag-slim[docling,groq,logfire]
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
See the main [`haiku.rag`](https://github.com/ggozad/haiku.rag) repository for:
|
||||
- Quick start guide
|
||||
- CLI examples
|
||||
- Python API usage
|
||||
- MCP server setup
|
||||
- A2A agent configuration
|
||||
|
||||
## Documentation
|
||||
|
||||
Full documentation: https://ggozad.github.io/haiku.rag/
|
||||
|
||||
- [Installation](https://ggozad.github.io/haiku.rag/installation/) - Provider setup
|
||||
- [Configuration](https://ggozad.github.io/haiku.rag/configuration/) - YAML configuration
|
||||
- [CLI](https://ggozad.github.io/haiku.rag/cli/) - Command reference
|
||||
- [Python API](https://ggozad.github.io/haiku.rag/python/) - Complete API docs
|
||||
|
|
@ -4,10 +4,6 @@ import logging
|
|||
from importlib.metadata import version as pkg_version
|
||||
from pathlib import Path
|
||||
|
||||
from rich.console import Console
|
||||
from rich.markdown import Markdown
|
||||
from rich.progress import Progress
|
||||
|
||||
from haiku.rag.client import HaikuRAG
|
||||
from haiku.rag.config import Config
|
||||
from haiku.rag.mcp import create_mcp_server
|
||||
|
|
@ -22,6 +18,9 @@ from haiku.rag.research.graph import (
|
|||
from haiku.rag.research.stream import stream_research_graph
|
||||
from haiku.rag.store.models.chunk import Chunk
|
||||
from haiku.rag.store.models.document import Document
|
||||
from rich.console import Console
|
||||
from rich.markdown import Markdown
|
||||
from rich.progress import Progress
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -59,7 +58,7 @@ class HaikuRAGApp:
|
|||
except Exception:
|
||||
ldb_version = "unknown"
|
||||
try:
|
||||
hr_version = pkg_version("haiku.rag")
|
||||
hr_version = pkg_version("haiku.rag-slim")
|
||||
except Exception:
|
||||
hr_version = "unknown"
|
||||
try:
|
||||
|
|
@ -211,12 +210,11 @@ class HaikuRAGApp:
|
|||
async with HaikuRAG(db_path=self.db_path) as self.client:
|
||||
try:
|
||||
if deep:
|
||||
from rich.console import Console
|
||||
|
||||
from haiku.rag.qa.deep.dependencies import DeepQAContext
|
||||
from haiku.rag.qa.deep.graph import build_deep_qa_graph
|
||||
from haiku.rag.qa.deep.nodes import DeepQAPlanNode
|
||||
from haiku.rag.qa.deep.state import DeepQADeps, DeepQAState
|
||||
from rich.console import Console
|
||||
|
||||
graph = build_deep_qa_graph()
|
||||
context = DeepQAContext(
|
||||
|
|
@ -1,12 +1,18 @@
|
|||
from typing import ClassVar
|
||||
|
||||
import tiktoken
|
||||
from docling.chunking import HybridChunker # type: ignore
|
||||
from docling_core.transforms.chunker.tokenizer.openai import OpenAITokenizer
|
||||
from docling_core.types.doc.document import DoclingDocument
|
||||
|
||||
from haiku.rag.config import Config
|
||||
|
||||
# Check if docling is available
|
||||
try:
|
||||
import docling # noqa: F401
|
||||
|
||||
DOCLING_AVAILABLE = True
|
||||
except ImportError:
|
||||
DOCLING_AVAILABLE = False
|
||||
|
||||
|
||||
class Chunker:
|
||||
"""A class that chunks text into smaller pieces for embedding and retrieval.
|
||||
|
|
@ -24,6 +30,13 @@ class Chunker:
|
|||
self,
|
||||
chunk_size: int = Config.processing.chunk_size,
|
||||
):
|
||||
if not DOCLING_AVAILABLE:
|
||||
raise ImportError(
|
||||
"Docling is required for chunking. "
|
||||
"Install with: pip install haiku.rag-slim[docling]"
|
||||
)
|
||||
from docling.chunking import HybridChunker # type: ignore
|
||||
|
||||
self.chunk_size = chunk_size
|
||||
tokenizer = OpenAITokenizer(
|
||||
tokenizer=tiktoken.encoding_for_model("gpt-4o"), max_tokens=chunk_size
|
||||
|
|
@ -36,7 +36,7 @@ async def check_version():
|
|||
|
||||
def version_callback(value: bool):
|
||||
if value:
|
||||
v = version("haiku.rag")
|
||||
v = version("haiku.rag-slim")
|
||||
typer.echo(f"haiku.rag version {v}")
|
||||
raise typer.Exit()
|
||||
|
||||
|
|
@ -353,7 +353,6 @@ def init_config(
|
|||
):
|
||||
"""Generate a YAML configuration file with defaults or from .env."""
|
||||
import yaml
|
||||
|
||||
from haiku.rag.config.loader import generate_default_config, load_config_from_env
|
||||
|
||||
if output.exists():
|
||||
|
|
@ -1,11 +1,17 @@
|
|||
from pathlib import Path
|
||||
from typing import ClassVar
|
||||
|
||||
from docling.document_converter import DocumentConverter
|
||||
from docling_core.types.doc.document import DoclingDocument
|
||||
|
||||
from haiku.rag.utils import text_to_docling_document
|
||||
|
||||
# Check if docling is available
|
||||
try:
|
||||
import docling # noqa: F401
|
||||
|
||||
DOCLING_AVAILABLE = True
|
||||
except ImportError:
|
||||
DOCLING_AVAILABLE = False
|
||||
|
||||
|
||||
class FileReader:
|
||||
# Extensions supported by docling
|
||||
|
|
@ -95,6 +101,13 @@ class FileReader:
|
|||
|
||||
if file_extension in FileReader.docling_extensions:
|
||||
# Use docling for complex document formats
|
||||
if not DOCLING_AVAILABLE:
|
||||
raise ImportError(
|
||||
"Docling is required for processing this file type. "
|
||||
"Install with: pip install haiku.rag-slim[docling]"
|
||||
)
|
||||
from docling.document_converter import DocumentConverter
|
||||
|
||||
converter = DocumentConverter()
|
||||
result = converter.convert(path)
|
||||
return result.document
|
||||
|
|
@ -113,5 +126,7 @@ class FileReader:
|
|||
# Fallback: try to read as text and convert to DoclingDocument
|
||||
content = path.read_text(encoding="utf-8")
|
||||
return text_to_docling_document(content, name=f"{path.stem}.md")
|
||||
except ImportError:
|
||||
raise
|
||||
except Exception:
|
||||
raise ValueError(f"Failed to parse file: {path}")
|
||||
|
|
@ -7,11 +7,10 @@ from pathlib import Path
|
|||
from uuid import uuid4
|
||||
|
||||
import lancedb
|
||||
from lancedb.pydantic import LanceModel, Vector
|
||||
from pydantic import Field
|
||||
|
||||
from haiku.rag.config import AppConfig, Config
|
||||
from haiku.rag.embeddings import get_embedder
|
||||
from lancedb.pydantic import LanceModel, Vector
|
||||
from pydantic import Field
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -189,7 +188,7 @@ class Store:
|
|||
try:
|
||||
from haiku.rag.store.upgrades import run_pending_upgrades
|
||||
|
||||
current_version = metadata.version("haiku.rag")
|
||||
current_version = metadata.version("haiku.rag-slim")
|
||||
db_version = self.get_haiku_version()
|
||||
|
||||
if db_version != "0.0.0":
|
||||
|
|
@ -199,9 +198,8 @@ class Store:
|
|||
# to the greater of the installed package version and the
|
||||
# highest available upgrade step version in code.
|
||||
try:
|
||||
from packaging.version import parse as _v
|
||||
|
||||
from haiku.rag.store.upgrades import upgrades as _steps
|
||||
from packaging.version import parse as _v
|
||||
|
||||
highest_step = max((_v(u.version) for u in _steps), default=None)
|
||||
effective_version = (
|
||||
|
|
@ -218,7 +216,7 @@ class Store:
|
|||
logger.warning(
|
||||
"Skipping upgrade due to error (db=%s -> pkg=%s): %s",
|
||||
self.get_haiku_version(),
|
||||
metadata.version("haiku.rag") if hasattr(metadata, "version") else "",
|
||||
metadata.version("haiku.rag-slim"),
|
||||
e,
|
||||
)
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ async def is_up_to_date() -> tuple[bool, Version, Version]:
|
|||
import httpx
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
running_version = parse(metadata.version("haiku.rag"))
|
||||
running_version = parse(metadata.version("haiku.rag-slim"))
|
||||
try:
|
||||
response = await client.get("https://pypi.org/pypi/haiku.rag/json")
|
||||
data = response.json()
|
||||
|
|
@ -103,9 +103,16 @@ def text_to_docling_document(text: str, name: str = "content.md"):
|
|||
Returns:
|
||||
A DoclingDocument created from the text content.
|
||||
"""
|
||||
# Lazy import docling deps to keep import-time light
|
||||
from docling.document_converter import DocumentConverter # type: ignore
|
||||
from docling_core.types.io import DocumentStream # type: ignore
|
||||
try:
|
||||
import docling # noqa: F401
|
||||
except ImportError as e:
|
||||
raise ImportError(
|
||||
"Docling is required for document conversion. "
|
||||
"Install with: pip install haiku.rag-slim[docling]"
|
||||
) from e
|
||||
|
||||
from docling.document_converter import DocumentConverter
|
||||
from docling_core.types.io import DocumentStream
|
||||
|
||||
bytes_io = BytesIO(text.encode("utf-8"))
|
||||
doc_stream = DocumentStream(name=name, stream=bytes_io)
|
||||
|
|
@ -168,11 +175,15 @@ def load_callable(path: str):
|
|||
def prefetch_models():
|
||||
"""Prefetch runtime models (Docling + Ollama as configured)."""
|
||||
import httpx
|
||||
from docling.utils.model_downloader import download_models
|
||||
|
||||
from haiku.rag.config import Config
|
||||
|
||||
download_models()
|
||||
try:
|
||||
from docling.utils.model_downloader import download_models
|
||||
|
||||
download_models()
|
||||
except ImportError:
|
||||
# Docling not installed, skip downloading docling models
|
||||
pass
|
||||
|
||||
# Collect Ollama models from config
|
||||
required_models: set[str] = set()
|
||||
66
haiku_rag_slim/pyproject.toml
Normal file
66
haiku_rag_slim/pyproject.toml
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
[project]
|
||||
|
||||
name = "haiku.rag-slim"
|
||||
description = "Agentic Retrieval Augmented Generation (RAG) with LanceDB - Minimal dependencies"
|
||||
version = "0.14.0"
|
||||
authors = [{ name = "Yiorgis Gozadinos", email = "ggozadinos@gmail.com" }]
|
||||
license = { text = "MIT" }
|
||||
readme = { file = "README.md", content-type = "text/markdown" }
|
||||
requires-python = ">=3.12"
|
||||
keywords = ["RAG", "lancedb", "vector-database", "ml", "mcp"]
|
||||
classifiers = [
|
||||
"Development Status :: 4 - Beta",
|
||||
"Environment :: Console",
|
||||
"Intended Audience :: Developers",
|
||||
"Operating System :: Microsoft :: Windows :: Windows 10",
|
||||
"Operating System :: Microsoft :: Windows :: Windows 11",
|
||||
"Operating System :: MacOS",
|
||||
"Operating System :: POSIX :: Linux",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3.13",
|
||||
"Typing :: Typed",
|
||||
]
|
||||
|
||||
dependencies = [
|
||||
"docling-core>=2.50.1",
|
||||
"httpx>=0.28.1",
|
||||
"lancedb>=0.25.2",
|
||||
"pathspec>=0.12.1",
|
||||
"pydantic>=2.12.3",
|
||||
"pydantic-ai-slim[openai,fastmcp,logfire]>=1.11.0",
|
||||
"python-dotenv>=1.2.1",
|
||||
"pyyaml>=6.0.3",
|
||||
"rich>=14.2.0",
|
||||
"tiktoken>=0.12.0",
|
||||
"typer>=0.19.2,<0.20.0",
|
||||
"watchfiles>=1.1.1",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
# Document processing
|
||||
docling = ["docling>=2.60.1"]
|
||||
# Embedding providers
|
||||
voyageai = ["voyageai>=0.3.5"]
|
||||
# Rerankers
|
||||
mxbai = ["mxbai-rerank>=0.1.6"]
|
||||
cohere = ["cohere>=5.0.0"]
|
||||
zeroentropy = ["zeroentropy>=0.1.0a6"]
|
||||
# Agent protocols
|
||||
a2a = ["fasta2a>=0.1.0", "pydantic-ai-slim[a2a]"]
|
||||
# Model providers (delegated to pydantic-ai-slim)
|
||||
anthropic = ["pydantic-ai-slim[anthropic]"]
|
||||
groq = ["pydantic-ai-slim[groq]"]
|
||||
google = ["pydantic-ai-slim[google]"]
|
||||
mistral = ["pydantic-ai-slim[mistral]"]
|
||||
bedrock = ["pydantic-ai-slim[bedrock]"]
|
||||
vertexai = ["pydantic-ai-slim[vertexai]"]
|
||||
|
||||
[project.scripts]
|
||||
haiku-rag = "haiku.rag.cli:cli"
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["haiku"]
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue