vector-graph-rag 0.1.4__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vector_graph_rag-0.2.0/AGENTS.md +1 -0
- vector_graph_rag-0.2.0/CLAUDE.md +92 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/PKG-INFO +83 -7
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/README.md +52 -6
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/api/main.py +1 -1
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/faq.md +27 -2
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/getting-started.md +46 -4
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/how-it-works.md +1 -1
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/index.md +4 -1
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/python-api.md +264 -15
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/rest-api.md +26 -5
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/use-cases.md +5 -5
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/evaluate.py +2 -2
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/import/FileUploader.tsx +1 -1
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/pyproject.toml +42 -2
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/__init__.py +1 -1
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/api/app.py +28 -4
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/config.py +16 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/graph/retriever.py +76 -3
- vector_graph_rag-0.2.0/src/vector_graph_rag/rag.py +1535 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/__init__.py +157 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/google.py +85 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/huggingface.py +135 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/jina.py +106 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/local.py +85 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/mistral.py +81 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/ollama.py +60 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/onnx.py +189 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/openai.py +83 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/utils.py +53 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embedding_providers/voyage.py +76 -0
- vector_graph_rag-0.2.0/src/vector_graph_rag/storage/embeddings.py +217 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/storage/milvus.py +158 -3
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/tests/conftest.py +5 -3
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/tests/test_api.py +15 -7
- vector_graph_rag-0.2.0/tests/test_embedding_providers.py +162 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/tests/test_milvus_store.py +56 -2
- vector_graph_rag-0.2.0/tests/test_rag_incremental.py +440 -0
- vector_graph_rag-0.2.0/tests/test_rag_metadata_filter.py +198 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/uv.lock +1299 -82
- vector_graph_rag-0.1.4/src/vector_graph_rag/rag.py +0 -767
- vector_graph_rag-0.1.4/src/vector_graph_rag/storage/embeddings.py +0 -335
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/.dockerignore +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/.env.example +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/.github/workflows/docs.yml +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/.github/workflows/release.yml +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/.gitignore +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/Dockerfile +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/LICENSE +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/api/__init__.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/api/schemas.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/assets/logo.png +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/assets/logo.svg +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/design-philosophy.md +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/evaluation.md +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/frontend.md +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/docs/stylesheets/custom.css +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/README.md +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/2wikimultihopqa.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/2wikimultihopqa_corpus.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/hotpotqa.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/hotpotqa_corpus.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/musique.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/musique_corpus.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/ner_cache/2wikimultihopqa_queries.named_entity_output.tsv +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/ner_cache/hotpotqa_queries.named_entity_output.tsv +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/ner_cache/hotpotqa_train_queries.named_entity_output.tsv +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/ner_cache/musique_queries.named_entity_output.tsv +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/ner_cache/sample_queries.named_entity_output.tsv +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/openie_2wikimultihopqa_results_ner_gpt-3.5-turbo-1106_6119.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/openie_hotpotqa_results_ner_gpt-3.5-turbo-1106_9221.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/openie_musique_results_ner_gpt-3.5-turbo-1106_11656.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/openie_test_sample_results_ner_gpt-3.5-turbo-1106_20.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/test_sample.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/evaluation/data/test_sample_corpus.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/.gitignore +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/README.md +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/eslint.config.js +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/index.html +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/package-lock.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/package.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/public/vite.svg +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/App.css +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/App.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/api/client.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/api/queries.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/assets/react.svg +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/graph/EntityNode.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/graph/GraphCanvas.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/graph/GraphLegend.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/graph/RelationEdge.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/graph/index.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/import/CreateGraphDialog.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/import/GraphSelector.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/import/GraphStatsPreview.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/import/ImportDialog.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/import/ImportProgress.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/import/ImportSettings.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/import/UrlInput.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/panels/AnswerPanel.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/panels/NodeDetailPanel.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/panels/index.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/search/SearchInput.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/search/index.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/settings/SettingsDialog.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/timeline/ProcessTimeline.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/timeline/index.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/ui/Header.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/ui/button.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/ui/dialog.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/ui/input.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/ui/label.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/ui/progress.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/ui/switch.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/components/ui/tabs.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/hooks/use-toast.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/index.css +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/main.tsx +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/stores/datasetStore.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/stores/graphStore.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/stores/searchStore.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/types/api.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/utils/cn.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/src/utils/graphLayout.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/tsconfig.app.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/tsconfig.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/tsconfig.node.json +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/frontend/vite.config.ts +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/mkdocs.yml +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/api/__init__.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/graph/__init__.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/graph/builder.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/graph/graph.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/graph/knowledge_graph.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/llm/__init__.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/llm/cache.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/llm/extractor.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/llm/reranker.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/loaders/__init__.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/loaders/chunker.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/loaders/converter.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/loaders/url_fetcher.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/models.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/src/vector_graph_rag/storage/__init__.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/tests/__init__.py +0 -0
- {vector_graph_rag-0.1.4 → vector_graph_rag-0.2.0}/tests/test_graph.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CLAUDE.md
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## What this is
|
|
6
|
+
|
|
7
|
+
Vector Graph RAG implements Graph RAG using **pure vector search in Milvus** — no graph database (Neo4j etc.). Knowledge-graph entities and relations are stored as vectors; the graph's adjacency is encoded as ID lists in each record's metadata, and "graph traversal" is implemented as repeated `query`/`search` calls against Milvus by those IDs. The key algorithmic bet is replacing iterative LLM agent loops (IRCoT, multi-step reflection) with a **single-pass LLM reranking** step.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
This is a `uv` + `pyproject.toml` project. Use `uv` directly — never `pip` or `uv pip`.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
uv sync --extra dev # install with dev deps (pytest, ruff)
|
|
15
|
+
uv sync --extra all # everything (dev + api + hf)
|
|
16
|
+
|
|
17
|
+
uv run pytest # run all tests
|
|
18
|
+
uv run pytest tests/test_graph.py # single file
|
|
19
|
+
uv run pytest tests/test_graph.py::test_name # single test
|
|
20
|
+
uv run pytest -k metadata_filter # by keyword
|
|
21
|
+
|
|
22
|
+
uv run ruff check . # lint
|
|
23
|
+
uv run ruff format . # format
|
|
24
|
+
|
|
25
|
+
# API server (canonical entrypoint — used by README and Dockerfile)
|
|
26
|
+
uv sync --extra api
|
|
27
|
+
uv run uvicorn vector_graph_rag.api.app:app --host 0.0.0.0 --port 8000
|
|
28
|
+
|
|
29
|
+
# Frontend (React + Vite)
|
|
30
|
+
cd frontend && npm install && npm run dev
|
|
31
|
+
|
|
32
|
+
# Evaluation (multi-hop QA benchmarks)
|
|
33
|
+
uv run python evaluation/evaluate.py --dataset musique --method graph
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Tests mock OpenAI and use Milvus Lite (a temp `.db` file per test via the `temp_milvus_uri` fixture in `tests/conftest.py`), so they run offline with no API key. `asyncio_mode = "auto"`, so async tests need no decorator.
|
|
37
|
+
|
|
38
|
+
## Architecture
|
|
39
|
+
|
|
40
|
+
### Indexing → Query pipeline
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
add_documents: Documents → TripletExtractor (LLM) → GraphBuilder → embeddings → MilvusStore
|
|
44
|
+
query: Question → EntityExtractor → vector search → SubGraph.expand → LLMReranker → AnswerGenerator
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`VectorGraphRAG` (`src/vector_graph_rag/rag.py`) is the user-facing facade that wires these components together. Read it first — its `add_documents` and `query` methods are the spine of the whole system.
|
|
48
|
+
|
|
49
|
+
### Three Milvus collections
|
|
50
|
+
|
|
51
|
+
`MilvusStore` (`storage/milvus.py`) manages **three collections** — `entities`, `relations`, `passages` (prefixed by `collection_prefix`). The graph structure lives entirely in metadata:
|
|
52
|
+
|
|
53
|
+
- **Entity** metadata → `relation_ids`, `passage_ids`
|
|
54
|
+
- **Relation** metadata → `entity_ids` (head, tail), `passage_ids`, plus structured `subject`/`predicate`/`object`
|
|
55
|
+
- **Passage** metadata → `entity_ids`, `relation_ids`, **plus arbitrary user metadata** (used for the `filter` feature)
|
|
56
|
+
|
|
57
|
+
Subgraph expansion (`graph/knowledge_graph.py`, `SubGraph`) is **lazy**: it holds IDs and fetches neighbor records from Milvus on demand during `expand(degree=...)` rather than loading the full graph into memory.
|
|
58
|
+
|
|
59
|
+
### Important data-flow detail
|
|
60
|
+
|
|
61
|
+
`add_documents` **drops and recreates all collections every call** (`rag.py` ~line 403) — it is a full rebuild, not an append. The retriever (`self._retriever`) is reset to `None` after any add and lazily rebuilt on the next query via `_ensure_retriever()`.
|
|
62
|
+
|
|
63
|
+
### Retrieval specifics (`graph/retriever.py`)
|
|
64
|
+
|
|
65
|
+
- Entity and relation searches each apply a **similarity threshold** (`entity_similarity_threshold` default `0.9`; relation default `-1.0` = keep all). Scores are kept when `score > threshold`.
|
|
66
|
+
- **Eviction strategy**: if expanded relations exceed `relation_number_threshold` (default 1000), a vector search re-ranks them down to the threshold. Below it, relations are sorted by ID to match HippoRAG's deterministic behavior.
|
|
67
|
+
- The `filter` parameter (a Milvus filter expression on passage metadata) flows through retrieval by first resolving allowed passage IDs, then filtering relations to those touching an allowed passage.
|
|
68
|
+
|
|
69
|
+
### Component map
|
|
70
|
+
|
|
71
|
+
- `llm/extractor.py` — `TripletExtractor` (doc → triplets) and `EntityExtractor` (query → entities); `processing_phrases` normalizes entity strings. Has an NER cache for evaluation (HippoRAG TSV format).
|
|
72
|
+
- `llm/reranker.py` — `LLMReranker` (single-pass relation reranking) and `AnswerGenerator`.
|
|
73
|
+
- `llm/cache.py` — disk cache for LLM responses (`use_llm_cache`).
|
|
74
|
+
- `graph/builder.py` — `GraphBuilder` turns triplets into entity/relation/passage records + adjacency maps.
|
|
75
|
+
- `graph/graph.py` — `Graph`, a higher-level CRUD interface over `MilvusStore` (used mainly by the API layer); entity/relation methods are private, users work at the passage level.
|
|
76
|
+
- `storage/embeddings.py` — `EmbeddingModel`, supports OpenAI and (optional `[hf]` extra) HuggingFace models.
|
|
77
|
+
|
|
78
|
+
### Configuration
|
|
79
|
+
|
|
80
|
+
`config.py` `Settings` is a pydantic-settings `BaseSettings`. All settings read from env with the **`VGRAG_` prefix** (e.g. `VGRAG_LLM_MODEL`) or a `.env` file. `VectorGraphRAG.__init__` kwargs override env. The OpenAI key falls back to plain `OPENAI_API_KEY`. Note the default `embedding_model` is `text-embedding-3-large` (dimension 3072) in `Settings`, while the `create_rag` factory and docstrings default to `text-embedding-3-small` — keep `embedding_dimension` consistent with whatever model you set.
|
|
81
|
+
|
|
82
|
+
### Two API directories — do not confuse them
|
|
83
|
+
|
|
84
|
+
- `src/vector_graph_rag/api/app.py` — **the canonical, packaged API.** This is what the README, Dockerfile, and `uvicorn vector_graph_rag.api.app:app` use. Edit this one.
|
|
85
|
+
- `api/` (repo root) — a separate standalone variant with a `sys.path` hack and its own `schemas.py`. Not the packaged entrypoint; treat as legacy unless a task explicitly concerns it.
|
|
86
|
+
|
|
87
|
+
## Conventions
|
|
88
|
+
|
|
89
|
+
- Code and comments in English. User-facing replies follow the user's language.
|
|
90
|
+
- Methods prefixed with `_` on `MilvusStore`/`Graph` (e.g. `_insert_entities`, `_search_relations`) are internal entity/relation operations — the intended public surface is passage-level.
|
|
91
|
+
- `Document` is `langchain_core.documents.Document`; pre-extracted triplets are passed via `metadata["triplets"]` as `[subject, predicate, object]` lists.
|
|
92
|
+
- PyTorch install index is backend-specific (CPU on macOS/arm Linux, CUDA 12.4 on x86 Linux) via `[tool.uv.sources]`; the Dockerfile rewrites this based on the `TORCH_BACKEND` build arg.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vector-graph-rag
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: A Graph RAG implementation using pure vector search with Milvus
|
|
5
5
|
Project-URL: Homepage, https://github.com/zilliztech/vector-graph-rag
|
|
6
6
|
Project-URL: Documentation, https://zilliztech.github.io/vector-graph-rag/
|
|
@@ -33,13 +33,24 @@ Requires-Dist: tenacity>=8.2.0
|
|
|
33
33
|
Requires-Dist: tiktoken>=0.5.0
|
|
34
34
|
Requires-Dist: tqdm>=4.65.0
|
|
35
35
|
Provides-Extra: all
|
|
36
|
+
Requires-Dist: einops>=0.8.2; extra == 'all'
|
|
36
37
|
Requires-Dist: fastapi>=0.109.0; extra == 'all'
|
|
38
|
+
Requires-Dist: google-genai>=1.0; extra == 'all'
|
|
39
|
+
Requires-Dist: httpx>=0.27; extra == 'all'
|
|
40
|
+
Requires-Dist: huggingface-hub>=0.20; extra == 'all'
|
|
41
|
+
Requires-Dist: mistralai>=1.0; extra == 'all'
|
|
42
|
+
Requires-Dist: ollama>=0.4; extra == 'all'
|
|
43
|
+
Requires-Dist: onnxruntime<1.24,>=1.17; (python_version == '3.10') and extra == 'all'
|
|
44
|
+
Requires-Dist: onnxruntime>=1.17; (python_version >= '3.11') and extra == 'all'
|
|
37
45
|
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'all'
|
|
38
46
|
Requires-Dist: pytest>=7.0.0; extra == 'all'
|
|
39
47
|
Requires-Dist: ruff>=0.1.0; extra == 'all'
|
|
48
|
+
Requires-Dist: sentence-transformers>=3.0; extra == 'all'
|
|
49
|
+
Requires-Dist: tokenizers>=0.15; extra == 'all'
|
|
40
50
|
Requires-Dist: torch>=2.0.0; extra == 'all'
|
|
41
51
|
Requires-Dist: transformers>=4.30.0; extra == 'all'
|
|
42
52
|
Requires-Dist: uvicorn[standard]>=0.27.0; extra == 'all'
|
|
53
|
+
Requires-Dist: voyageai>=0.3; extra == 'all'
|
|
43
54
|
Provides-Extra: api
|
|
44
55
|
Requires-Dist: fastapi>=0.109.0; extra == 'api'
|
|
45
56
|
Requires-Dist: uvicorn[standard]>=0.27.0; extra == 'api'
|
|
@@ -49,13 +60,32 @@ Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
|
49
60
|
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
50
61
|
Provides-Extra: docs
|
|
51
62
|
Requires-Dist: mkdocs-material>=9.0.0; extra == 'docs'
|
|
63
|
+
Provides-Extra: google
|
|
64
|
+
Requires-Dist: google-genai>=1.0; extra == 'google'
|
|
52
65
|
Provides-Extra: hf
|
|
53
66
|
Requires-Dist: torch>=2.0.0; extra == 'hf'
|
|
54
67
|
Requires-Dist: transformers>=4.30.0; extra == 'hf'
|
|
68
|
+
Provides-Extra: jina
|
|
69
|
+
Requires-Dist: httpx>=0.27; extra == 'jina'
|
|
55
70
|
Provides-Extra: loaders
|
|
56
71
|
Requires-Dist: lxml-html-clean; extra == 'loaders'
|
|
57
72
|
Requires-Dist: markitdown[docx,pdf]>=0.1.4; extra == 'loaders'
|
|
58
73
|
Requires-Dist: trafilatura>=2.0.0; extra == 'loaders'
|
|
74
|
+
Provides-Extra: local
|
|
75
|
+
Requires-Dist: einops>=0.8.2; extra == 'local'
|
|
76
|
+
Requires-Dist: sentence-transformers>=3.0; extra == 'local'
|
|
77
|
+
Requires-Dist: torch>=2.0.0; extra == 'local'
|
|
78
|
+
Provides-Extra: mistral
|
|
79
|
+
Requires-Dist: mistralai>=1.0; extra == 'mistral'
|
|
80
|
+
Provides-Extra: ollama
|
|
81
|
+
Requires-Dist: ollama>=0.4; extra == 'ollama'
|
|
82
|
+
Provides-Extra: onnx
|
|
83
|
+
Requires-Dist: huggingface-hub>=0.20; extra == 'onnx'
|
|
84
|
+
Requires-Dist: onnxruntime<1.24,>=1.17; (python_version == '3.10') and extra == 'onnx'
|
|
85
|
+
Requires-Dist: onnxruntime>=1.17; (python_version >= '3.11') and extra == 'onnx'
|
|
86
|
+
Requires-Dist: tokenizers>=0.15; extra == 'onnx'
|
|
87
|
+
Provides-Extra: voyage
|
|
88
|
+
Requires-Dist: voyageai>=0.3; extra == 'voyage'
|
|
59
89
|
Description-Content-Type: text/markdown
|
|
60
90
|
|
|
61
91
|
<h1 align="center">
|
|
@@ -112,12 +142,15 @@ uv add "vector-graph-rag[loaders]"
|
|
|
112
142
|
</details>
|
|
113
143
|
|
|
114
144
|
<details>
|
|
115
|
-
<summary><b>With
|
|
145
|
+
<summary><b>With additional embedding providers</b></summary>
|
|
116
146
|
|
|
117
147
|
```bash
|
|
118
|
-
pip install "vector-graph-rag[hf]"
|
|
148
|
+
pip install "vector-graph-rag[hf]" # HuggingFace transformers
|
|
149
|
+
pip install "vector-graph-rag[ollama]" # Ollama
|
|
150
|
+
pip install "vector-graph-rag[jina]" # Jina AI
|
|
151
|
+
pip install "vector-graph-rag[all]" # all optional providers
|
|
119
152
|
# or
|
|
120
|
-
uv add "vector-graph-rag[
|
|
153
|
+
uv add "vector-graph-rag[all]"
|
|
121
154
|
```
|
|
122
155
|
|
|
123
156
|
</details>
|
|
@@ -129,7 +162,7 @@ from vector_graph_rag import VectorGraphRAG
|
|
|
129
162
|
|
|
130
163
|
rag = VectorGraphRAG() # reads OPENAI_API_KEY from environment
|
|
131
164
|
|
|
132
|
-
rag.
|
|
165
|
+
rag.rebuild_texts([
|
|
133
166
|
"Albert Einstein developed the theory of relativity.",
|
|
134
167
|
"The theory of relativity revolutionized our understanding of space and time.",
|
|
135
168
|
])
|
|
@@ -146,7 +179,7 @@ print(result.answer)
|
|
|
146
179
|
Skip LLM extraction if you already have knowledge graph triplets:
|
|
147
180
|
|
|
148
181
|
```python
|
|
149
|
-
rag.
|
|
182
|
+
rag.rebuild_documents_with_triplets([
|
|
150
183
|
{
|
|
151
184
|
"passage": "Einstein developed relativity at Princeton.",
|
|
152
185
|
"triplets": [
|
|
@@ -159,6 +192,47 @@ rag.add_documents_with_triplets([
|
|
|
159
192
|
|
|
160
193
|
</details>
|
|
161
194
|
|
|
195
|
+
<details>
|
|
196
|
+
<summary>🔄 <b>Incremental document updates</b> — click to expand</summary>
|
|
197
|
+
|
|
198
|
+
Use `upsert_documents_by_source()` when a source file, message, or page is
|
|
199
|
+
created or modified. In Vector Graph RAG, a `Document` is a passage/chunk; the
|
|
200
|
+
source object is identified by `metadata["source"]` or the explicit `source`
|
|
201
|
+
argument. The method replaces only that source's chunks and graph references.
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
from langchain_core.documents import Document
|
|
205
|
+
|
|
206
|
+
rag.upsert_documents_by_source(
|
|
207
|
+
documents=[
|
|
208
|
+
Document(
|
|
209
|
+
page_content="Einstein developed relativity at Princeton.",
|
|
210
|
+
metadata={
|
|
211
|
+
"source": "sharepoint:file-123",
|
|
212
|
+
"triplets": [
|
|
213
|
+
["Einstein", "developed", "relativity"],
|
|
214
|
+
["Einstein", "worked at", "Princeton"],
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
),
|
|
218
|
+
],
|
|
219
|
+
extract_triplets=False,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
rag.delete_documents_by_source("sharepoint:file-123")
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
> **Migration note:** v0.1.5 exposed `upsert_documents(document_id=...)` and
|
|
226
|
+
> `delete_documents(document_id)`. These names were removed in v0.2.0 because
|
|
227
|
+
> `Document` means passage/chunk in this project. Use the `*_by_source()` APIs
|
|
228
|
+
> shown above.
|
|
229
|
+
|
|
230
|
+
The legacy `add_*` ingestion helpers rebuild the full knowledge base and are planned
|
|
231
|
+
for removal in v1.0.0. For explicit full refreshes, use `rebuild_texts()`,
|
|
232
|
+
`rebuild_documents()`, or `rebuild_documents_with_triplets()`.
|
|
233
|
+
|
|
234
|
+
</details>
|
|
235
|
+
|
|
162
236
|
<details>
|
|
163
237
|
<summary>🌐 <b>Import from URLs and files</b> — click to expand</summary>
|
|
164
238
|
|
|
@@ -175,7 +249,7 @@ result = importer.import_sources([
|
|
|
175
249
|
])
|
|
176
250
|
|
|
177
251
|
rag = VectorGraphRAG(milvus_uri="./my_graph.db")
|
|
178
|
-
rag.
|
|
252
|
+
rag.rebuild_documents(result.documents, extract_triplets=True)
|
|
179
253
|
|
|
180
254
|
result = rag.query("What did Einstein discover?")
|
|
181
255
|
print(result.answer)
|
|
@@ -190,6 +264,7 @@ print(result.answer)
|
|
|
190
264
|
rag = VectorGraphRAG(
|
|
191
265
|
milvus_uri="./my_data.db", # or remote Milvus / Zilliz Cloud
|
|
192
266
|
llm_model="gpt-4o",
|
|
267
|
+
embedding_provider="openai",
|
|
193
268
|
embedding_model="text-embedding-3-large",
|
|
194
269
|
collection_prefix="my_project", # isolate multiple datasets
|
|
195
270
|
)
|
|
@@ -199,6 +274,7 @@ All settings can also be configured via environment variables with `VGRAG_` pref
|
|
|
199
274
|
|
|
200
275
|
```bash
|
|
201
276
|
VGRAG_LLM_MODEL=gpt-4o
|
|
277
|
+
VGRAG_EMBEDDING_PROVIDER=openai
|
|
202
278
|
VGRAG_EMBEDDING_MODEL=text-embedding-3-large
|
|
203
279
|
VGRAG_MILVUS_URI=http://localhost:19530
|
|
204
280
|
```
|
|
@@ -52,12 +52,15 @@ uv add "vector-graph-rag[loaders]"
|
|
|
52
52
|
</details>
|
|
53
53
|
|
|
54
54
|
<details>
|
|
55
|
-
<summary><b>With
|
|
55
|
+
<summary><b>With additional embedding providers</b></summary>
|
|
56
56
|
|
|
57
57
|
```bash
|
|
58
|
-
pip install "vector-graph-rag[hf]"
|
|
58
|
+
pip install "vector-graph-rag[hf]" # HuggingFace transformers
|
|
59
|
+
pip install "vector-graph-rag[ollama]" # Ollama
|
|
60
|
+
pip install "vector-graph-rag[jina]" # Jina AI
|
|
61
|
+
pip install "vector-graph-rag[all]" # all optional providers
|
|
59
62
|
# or
|
|
60
|
-
uv add "vector-graph-rag[
|
|
63
|
+
uv add "vector-graph-rag[all]"
|
|
61
64
|
```
|
|
62
65
|
|
|
63
66
|
</details>
|
|
@@ -69,7 +72,7 @@ from vector_graph_rag import VectorGraphRAG
|
|
|
69
72
|
|
|
70
73
|
rag = VectorGraphRAG() # reads OPENAI_API_KEY from environment
|
|
71
74
|
|
|
72
|
-
rag.
|
|
75
|
+
rag.rebuild_texts([
|
|
73
76
|
"Albert Einstein developed the theory of relativity.",
|
|
74
77
|
"The theory of relativity revolutionized our understanding of space and time.",
|
|
75
78
|
])
|
|
@@ -86,7 +89,7 @@ print(result.answer)
|
|
|
86
89
|
Skip LLM extraction if you already have knowledge graph triplets:
|
|
87
90
|
|
|
88
91
|
```python
|
|
89
|
-
rag.
|
|
92
|
+
rag.rebuild_documents_with_triplets([
|
|
90
93
|
{
|
|
91
94
|
"passage": "Einstein developed relativity at Princeton.",
|
|
92
95
|
"triplets": [
|
|
@@ -99,6 +102,47 @@ rag.add_documents_with_triplets([
|
|
|
99
102
|
|
|
100
103
|
</details>
|
|
101
104
|
|
|
105
|
+
<details>
|
|
106
|
+
<summary>🔄 <b>Incremental document updates</b> — click to expand</summary>
|
|
107
|
+
|
|
108
|
+
Use `upsert_documents_by_source()` when a source file, message, or page is
|
|
109
|
+
created or modified. In Vector Graph RAG, a `Document` is a passage/chunk; the
|
|
110
|
+
source object is identified by `metadata["source"]` or the explicit `source`
|
|
111
|
+
argument. The method replaces only that source's chunks and graph references.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from langchain_core.documents import Document
|
|
115
|
+
|
|
116
|
+
rag.upsert_documents_by_source(
|
|
117
|
+
documents=[
|
|
118
|
+
Document(
|
|
119
|
+
page_content="Einstein developed relativity at Princeton.",
|
|
120
|
+
metadata={
|
|
121
|
+
"source": "sharepoint:file-123",
|
|
122
|
+
"triplets": [
|
|
123
|
+
["Einstein", "developed", "relativity"],
|
|
124
|
+
["Einstein", "worked at", "Princeton"],
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
),
|
|
128
|
+
],
|
|
129
|
+
extract_triplets=False,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
rag.delete_documents_by_source("sharepoint:file-123")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
> **Migration note:** v0.1.5 exposed `upsert_documents(document_id=...)` and
|
|
136
|
+
> `delete_documents(document_id)`. These names were removed in v0.2.0 because
|
|
137
|
+
> `Document` means passage/chunk in this project. Use the `*_by_source()` APIs
|
|
138
|
+
> shown above.
|
|
139
|
+
|
|
140
|
+
The legacy `add_*` ingestion helpers rebuild the full knowledge base and are planned
|
|
141
|
+
for removal in v1.0.0. For explicit full refreshes, use `rebuild_texts()`,
|
|
142
|
+
`rebuild_documents()`, or `rebuild_documents_with_triplets()`.
|
|
143
|
+
|
|
144
|
+
</details>
|
|
145
|
+
|
|
102
146
|
<details>
|
|
103
147
|
<summary>🌐 <b>Import from URLs and files</b> — click to expand</summary>
|
|
104
148
|
|
|
@@ -115,7 +159,7 @@ result = importer.import_sources([
|
|
|
115
159
|
])
|
|
116
160
|
|
|
117
161
|
rag = VectorGraphRAG(milvus_uri="./my_graph.db")
|
|
118
|
-
rag.
|
|
162
|
+
rag.rebuild_documents(result.documents, extract_triplets=True)
|
|
119
163
|
|
|
120
164
|
result = rag.query("What did Einstein discover?")
|
|
121
165
|
print(result.answer)
|
|
@@ -130,6 +174,7 @@ print(result.answer)
|
|
|
130
174
|
rag = VectorGraphRAG(
|
|
131
175
|
milvus_uri="./my_data.db", # or remote Milvus / Zilliz Cloud
|
|
132
176
|
llm_model="gpt-4o",
|
|
177
|
+
embedding_provider="openai",
|
|
133
178
|
embedding_model="text-embedding-3-large",
|
|
134
179
|
collection_prefix="my_project", # isolate multiple datasets
|
|
135
180
|
)
|
|
@@ -139,6 +184,7 @@ All settings can also be configured via environment variables with `VGRAG_` pref
|
|
|
139
184
|
|
|
140
185
|
```bash
|
|
141
186
|
VGRAG_LLM_MODEL=gpt-4o
|
|
187
|
+
VGRAG_EMBEDDING_PROVIDER=openai
|
|
142
188
|
VGRAG_EMBEDDING_MODEL=text-embedding-3-large
|
|
143
189
|
VGRAG_MILVUS_URI=http://localhost:19530
|
|
144
190
|
```
|
|
@@ -252,7 +252,7 @@ async def add_documents(documents: list[str]):
|
|
|
252
252
|
"""Add documents to the knowledge graph."""
|
|
253
253
|
try:
|
|
254
254
|
rag = get_rag()
|
|
255
|
-
rag.
|
|
255
|
+
rag.rebuild_texts(documents)
|
|
256
256
|
return {"status": "ok", "message": f"Added {len(documents)} documents"}
|
|
257
257
|
except Exception as e:
|
|
258
258
|
raise HTTPException(status_code=500, detail=str(e))
|
|
@@ -37,11 +37,32 @@ Frequently asked questions about Vector Graph RAG — covering when to use it, c
|
|
|
37
37
|
result = importer.import_sources(["/path/to/large_document.pdf"])
|
|
38
38
|
|
|
39
39
|
rag = VectorGraphRAG(milvus_uri="./my_graph.db")
|
|
40
|
-
rag.
|
|
40
|
+
rag.rebuild_documents(result.documents, extract_triplets=True)
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
For very large corpora, consider using a remote Milvus instance rather than Milvus Lite for better performance and scalability.
|
|
44
44
|
|
|
45
|
+
??? note "How do I update or delete one source document?"
|
|
46
|
+
Use `upsert_documents_by_source()` for source create/update and `delete_documents_by_source()` for delete. A source can be a file, web page, message, or another business-level object. Its parsed chunks are passed as LangChain `Document` objects, and each chunk should carry the same stable `metadata["source"]` value.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from langchain_core.documents import Document
|
|
50
|
+
|
|
51
|
+
rag.upsert_documents_by_source(
|
|
52
|
+
documents=[
|
|
53
|
+
Document(
|
|
54
|
+
page_content="Updated document chunk text.",
|
|
55
|
+
metadata={"source": "file-123", "page": 1},
|
|
56
|
+
)
|
|
57
|
+
],
|
|
58
|
+
extract_triplets=True,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
rag.delete_documents_by_source("file-123")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Incremental updates replace only the chunks and graph references for that source value. They are not transactionally atomic, so avoid interrupting or concurrently mutating the same collection prefix during an update.
|
|
65
|
+
|
|
45
66
|
??? note "Can I use local/open-source LLMs?"
|
|
46
67
|
Yes. Vector Graph RAG uses the OpenAI-compatible API format, so any LLM that exposes an OpenAI-compatible endpoint will work. This includes local models served via [Ollama](https://ollama.com/), [vLLM](https://github.com/vllm-project/vllm), [LM Studio](https://lmstudio.ai/), or any other OpenAI-compatible server. You can configure the base URL and model name when initializing the RAG instance. Keep in mind that triplet extraction and reranking quality depend heavily on the LLM's capability — weaker models may produce incomplete or inaccurate triplets, which directly affects retrieval quality. For best results, use a model with strong instruction-following and reasoning abilities.
|
|
47
68
|
|
|
@@ -70,7 +91,11 @@ Frequently asked questions about Vector Graph RAG — covering when to use it, c
|
|
|
70
91
|
```
|
|
71
92
|
|
|
72
93
|
??? note "Can I use my own embeddings?"
|
|
73
|
-
|
|
94
|
+
Yes. New applications should set both `embedding_provider` and `embedding_model`.
|
|
95
|
+
Supported providers are `openai`, `huggingface`, `google`/`gemini`, `voyage`, `jina`, `mistral`, `ollama`, `local`, and `onnx`.
|
|
96
|
+
Install the matching optional extra, such as `vector-graph-rag[hf]`, `vector-graph-rag[ollama]`, or `vector-graph-rag[all]`.
|
|
97
|
+
If `embedding_provider` is omitted, Vector Graph RAG keeps a legacy provider inference path for compatibility, but that path is deprecated and planned for removal in v1.0.0.
|
|
98
|
+
The embedding dimensionality is detected automatically. All entities, relations, and passages in a single graph must use the same embedding provider and model — mixing embeddings within one collection prefix is not supported.
|
|
74
99
|
|
|
75
100
|
??? note "How do I deploy to production?"
|
|
76
101
|
For production deployments, use a remote Milvus instance instead of Milvus Lite for better performance, scalability, and persistence. Run the FastAPI backend behind a reverse proxy (e.g., Nginx) with appropriate rate limiting and authentication. The frontend can be built as static files and served from any CDN or static file server.
|
|
@@ -26,6 +26,12 @@
|
|
|
26
26
|
pip install "vector-graph-rag[hf]"
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
=== "With all embedding providers"
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install "vector-graph-rag[all]"
|
|
33
|
+
```
|
|
34
|
+
|
|
29
35
|
!!! note "Prerequisites"
|
|
30
36
|
- Python 3.9+
|
|
31
37
|
- An OpenAI API key (set `OPENAI_API_KEY` environment variable)
|
|
@@ -37,7 +43,7 @@ from vector_graph_rag import VectorGraphRAG
|
|
|
37
43
|
|
|
38
44
|
rag = VectorGraphRAG() # reads OPENAI_API_KEY from environment
|
|
39
45
|
|
|
40
|
-
rag.
|
|
46
|
+
rag.rebuild_texts([
|
|
41
47
|
"Albert Einstein developed the theory of relativity.",
|
|
42
48
|
"The theory of relativity revolutionized our understanding of space and time.",
|
|
43
49
|
])
|
|
@@ -57,6 +63,7 @@ print(result.answer)
|
|
|
57
63
|
rag = VectorGraphRAG(
|
|
58
64
|
milvus_uri="./my_data.db", # local file (Milvus Lite)
|
|
59
65
|
llm_model="gpt-4o", # LLM for extraction and reranking
|
|
66
|
+
embedding_provider="openai", # embedding provider
|
|
60
67
|
embedding_model="text-embedding-3-large", # embedding model
|
|
61
68
|
)
|
|
62
69
|
```
|
|
@@ -126,10 +133,13 @@ finance_rag = VectorGraphRAG(milvus_uri="./data.db", collection_prefix="finance"
|
|
|
126
133
|
|
|
127
134
|
## Adding Documents
|
|
128
135
|
|
|
136
|
+
!!! warning "Full rebuild vs incremental updates"
|
|
137
|
+
`add_texts()`, `add_documents()`, and `add_documents_with_triplets()` rebuild the full knowledge base for the current collection prefix. These legacy convenience APIs are planned for removal in v1.0.0. Use `rebuild_texts()`, `rebuild_documents()`, or `rebuild_documents_with_triplets()` for full refreshes. For source create/update/delete flows, use `upsert_documents_by_source()` and `delete_documents_by_source()`.
|
|
138
|
+
|
|
129
139
|
### From Text Strings
|
|
130
140
|
|
|
131
141
|
```python
|
|
132
|
-
rag.
|
|
142
|
+
rag.rebuild_texts([
|
|
133
143
|
"Einstein developed relativity at Princeton.",
|
|
134
144
|
"The theory changed modern physics.",
|
|
135
145
|
])
|
|
@@ -140,7 +150,7 @@ rag.add_texts([
|
|
|
140
150
|
Skip LLM extraction if you already have knowledge graph triplets:
|
|
141
151
|
|
|
142
152
|
```python
|
|
143
|
-
rag.
|
|
153
|
+
rag.rebuild_documents_with_triplets([
|
|
144
154
|
{
|
|
145
155
|
"passage": "Einstein developed relativity at Princeton.",
|
|
146
156
|
"triplets": [
|
|
@@ -166,12 +176,44 @@ result = importer.import_sources([
|
|
|
166
176
|
])
|
|
167
177
|
|
|
168
178
|
rag = VectorGraphRAG(milvus_uri="./my_graph.db")
|
|
169
|
-
rag.
|
|
179
|
+
rag.rebuild_documents(result.documents, extract_triplets=True)
|
|
170
180
|
```
|
|
171
181
|
|
|
172
182
|
!!! warning "Loader dependencies"
|
|
173
183
|
Install with `pip install "vector-graph-rag[loaders]"` to enable URL fetching and document conversion.
|
|
174
184
|
|
|
185
|
+
### Incremental Updates
|
|
186
|
+
|
|
187
|
+
Use `upsert_documents_by_source()` when a source file, page, or message is created or modified. In Vector Graph RAG, a `Document` is a passage/chunk, and `metadata["source"]` identifies the source object whose chunks should be replaced.
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from langchain_core.documents import Document
|
|
191
|
+
|
|
192
|
+
rag.upsert_documents_by_source(
|
|
193
|
+
documents=[
|
|
194
|
+
Document(
|
|
195
|
+
page_content="Einstein developed relativity at Princeton.",
|
|
196
|
+
metadata={
|
|
197
|
+
"source": "sharepoint:file-123",
|
|
198
|
+
"triplets": [
|
|
199
|
+
["Einstein", "developed", "relativity"],
|
|
200
|
+
["Einstein", "worked at", "Princeton"],
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
)
|
|
204
|
+
],
|
|
205
|
+
extract_triplets=False,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
rag.delete_documents_by_source("sharepoint:file-123")
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
!!! warning "v0.2.0 migration"
|
|
212
|
+
`upsert_documents(document_id=...)` and `delete_documents(document_id)` were removed because `Document` means passage/chunk in this project. Use `upsert_documents_by_source()` and `delete_documents_by_source()` with a stable `metadata["source"]` value instead.
|
|
213
|
+
|
|
214
|
+
!!! note "Consistency model"
|
|
215
|
+
Incremental updates perform a source-level cascade across passages, entities, and relations. They are not transactionally atomic, so avoid interrupting or concurrently mutating the same collection prefix during an update.
|
|
216
|
+
|
|
175
217
|
## Querying
|
|
176
218
|
|
|
177
219
|
### Full Query Result
|
|
@@ -223,4 +223,4 @@ flowchart TD
|
|
|
223
223
|
Triplet extraction and reranking quality depends heavily on the underlying LLM's capability. Weaker models may produce incomplete or inaccurate triplets, which directly affects retrieval quality.
|
|
224
224
|
|
|
225
225
|
!!! warning "Graph Consistency"
|
|
226
|
-
The knowledge graph topology is maintained as a logical layer on top of Milvus via cross-referenced ID fields. Since Milvus does not support transactions, multi-step mutations (e.g., cascade
|
|
226
|
+
The knowledge graph topology is maintained as a logical layer on top of Milvus via cross-referenced ID fields. Since Milvus does not support transactions, multi-step mutations (e.g., source-level cascade updates) are not atomic and may leave inconsistent state if interrupted. Use `rebuild_documents()` for initial bulk indexing or full refreshes, and use `upsert_documents_by_source()` / `delete_documents_by_source()` for source updates when the write operation is expected to run to completion.
|
|
@@ -104,7 +104,7 @@ from vector_graph_rag import VectorGraphRAG
|
|
|
104
104
|
|
|
105
105
|
rag = VectorGraphRAG() # reads OPENAI_API_KEY from environment
|
|
106
106
|
|
|
107
|
-
rag.
|
|
107
|
+
rag.rebuild_texts([
|
|
108
108
|
"Albert Einstein developed the theory of relativity.",
|
|
109
109
|
"The theory of relativity revolutionized our understanding of space and time.",
|
|
110
110
|
])
|
|
@@ -113,6 +113,9 @@ result = rag.query("What did Einstein develop?")
|
|
|
113
113
|
print(result.answer)
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
+
!!! note "Ingestion semantics"
|
|
117
|
+
The legacy `add_*` ingestion helpers rebuild the full knowledge base and are planned for removal in v1.0.0. Use `rebuild_texts()`, `rebuild_documents()`, or `rebuild_documents_with_triplets()` for full refreshes, and use `upsert_documents_by_source()` / `delete_documents_by_source()` when a source file, page, or message changes later.
|
|
118
|
+
|
|
116
119
|
!!! tip "Getting Started"
|
|
117
120
|
See the [Getting Started](getting-started.md) guide for installation and configuration options.
|
|
118
121
|
|