A trans-temporal RAG system over Immanuel Kant’s corpus: Streamlit UI, ChromaDB semantic search, and optional Neo4j Graph-RAG. Default platform: Linux. Run all commands from the project root unless noted otherwise.
Prerequisites
torch, chromadb, pydantic).src/Text_2_speech (SadTalker): Linux + ffmpeg in PATH, plus model weights under src/Text_2_speech/checkpoints/.Create the venv and install dependencies
cd /path/to/Incarnation_Kant
# Full init: venv + pip install + crawl Korpora (see section A.4)
python initialize.py
# Or skip crawling and only set up env + deps:
python initialize.py --skip-download
# If you also need Text_2_speech dependencies:
python initialize.py --skip-download --with-text2speech
Activate the virtual environment
source .venv/bin/activate
Secrets
Create a .env file in the project root (do not commit it). At minimum for the web app:
GOOGLE_API_KEY=your_google_generative_ai_key
Optional for Graph-RAG build and Neo4j (see section A.3):
DEEPSEEK_API_KEY=your_deepseek_key
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_neo4j_password
src/config.py loads .env via python-dotenv. Prefer .env for secrets; do not copy API keys into config/settings.yaml (that file may contain placeholders—treat them as non-authoritative).
Non-secret settings
config/settings.yaml — app title, LLM model names, database paths, database.backend (chromadb vs neo4j), etc.database: block (duplicate keys in YAML can be confusing).Config file
.streamlit/config.toml — e.g. port = 8501, address = "0.0.0.0", headless = true.Point Streamlit at the config directory
export STREAMLIT_CONFIG_DIR="$(pwd)/.streamlit"
Caches (recommended)
app/main.py sets Hugging Face and temp dirs under .venv/.cache and .venv/.tmp when you run the app. For manual runs you can mirror run.sh:
export HF_HOME="$(pwd)/.venv/.cache/huggingface"
export TORCH_HOME="$(pwd)/.venv/.cache/torch"
export XDG_CACHE_HOME="$(pwd)/.venv/.cache"
API key
The Streamlit sidebar can set GOOGLE_API_KEY for the session; otherwise the app reads GOOGLE_API_KEY from .env or settings.llm.api_key (see app/main.py).
Known issue: run.sh currently uses hardcoded paths under /Data/Incarnation_Kant/. If you clone elsewhere, either edit run.sh or use manual startup (section B.2) with the exports above.
When you need it
database.backend to chromadb (or omit) — no Neo4j required for basic Q&A.DEEPSEEK_API_KEY for extraction during graph build.Connection
Set NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD in .env (same values can be mirrored under neo4j: in config/settings.yaml for documentation—env wins for overrides in load_config()).
Enable graph retrieval in the app
In config/settings.yaml:
database:
backend: "neo4j"
Bundled Neo4j (this repo)
A community distribution lives under neo4j-server/ (Neo4j 5.26.x). From that directory:
cd neo4j-server
./bin/neo4j-admin server console
bolt://localhost:7687).http://localhost:7474 (first run: set password to match NEO4J_PASSWORD).Pre-built graph store (neo4j-server/data)
The repo does not ship neo4j-server/ (it is gitignored). To use a ready-made Neo4j data directory instead of running build_graph_rag from scratch:
data.zip from Google Drive (sign in if the link requires it).neo4j-server/ — use the same Neo4j 5.x line as the project (see “Bundled Neo4j” above, e.g. 5.26.x). A store built with one minor version may not start on another; align versions with whoever produced the archive.neo4j-server/data/ directory so it does not mix with the archive.neo4j-server/data/ (you should see paths like neo4j-server/data/databases/ and neo4j-server/data/dbms/). If the zip contains a top-level data/ folder, place that folder as neo4j-server/data (not neo4j-server/data/data/).NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD in .env to match the user/password that were set when this database was created (the store on disk is tied to that password). If you only changed the password in the UI after import, use the current password.database.backend: "neo4j" in config/settings.yaml when you want Graph-RAG. The zip only provides the Neo4j graph; ChromaDB under data/chromadb is still built separately by ingest (and may be used as fallback depending on configuration).Alternative: install Neo4j via package manager or use Neo4j Aura; point NEO4J_URI accordingly.
initialize.py crawls korpora.org (Kant section) and writes HTML under data/raw/ (default layout includes data/raw/kant/ for the cleaner).
# Already have venv + deps; only (re)download:
python initialize.py --skip-venv --skip-install
Useful flags: --skip-download, --max-failure-rate, --max-depth (see initialize.py).
Note: After success, initialize.py may still print a legacy hint to scripts/build_database.py. That script does not exist. Use the pipeline in section A.5 instead.
Always run these from the project root with the venv activated.
| Step | Command | Output |
|---|---|---|
| 1. Clean raw HTML → JSONL | python -m src.database.cleaner | data/cleaned/*.jsonl (defaults: --input-dir data/raw/kant, --output-dir data/cleaned) |
| 2. Build semantic chunks | python -m src.database.build_chunks | data/chunks/*.jsonl |
| 3. Build ChromaDB vectors | python -m src.database.ingest | ./data/chromadb (defaults inside ingest.py; uses BGE-M3-style embedding pipeline) |
Optional: Graph-RAG (Neo4j)
Requires running Neo4j, DEEPSEEK_API_KEY, and existing chunks:
python -m src.database.build_graph_rag
python -m src.database.build_graph_rag --limit 20
python -m src.database.build_graph_rag --resume
Optional: entity resolution (SAME_AS edges between concepts)
python -m src.database.resolve_entities
See report.md for parameters, checkpoints, and runtime behavior.
src/Text_2_speech (SadTalker)src/Text_2_speech is an optional talking-head / text-to-speech module. It is independent from the default RAG pipeline.
Environment requirements
.venv) is supported.ffmpeg must be available from command line.src/Text_2_speech/checkpoints/ (required by src/Text_2_speech/inference.py and src/Text_2_speech/src/utils/init_path.py).Install dependencies
# from project root
source .venv/bin/activate
pip install -r requirements-text2speech.txt
Or use initializer:
python initialize.py --skip-download --with-text2speech
Compute requirements (practical guidance)
gfpgan / RestoreFormer).Run quick demo
python src/Text_2_speech/scripts/quick_demo_main.py \
--driven-audio /path/to/audio.wav \
--source-image /path/to/image.png \
--result-dir ./src/Text_2_speech/results \
--preprocess full \
--enhancer gfpgan
If examples/source_image does not exist in your local copy, always pass --source-image explicitly.
Streamlit integration (app/main.py)
500px-Immanuel_Kant_-_Gemaelde_1.jpg exists in the project root, it is used first. Otherwise the first request may download into data/assets/kant_portrait.* (Wikipedia HTML URLs are handled via og:image). Later runs use local files only.pip install -r requirements-text2speech.txt (includes Coqui TTS).cd /path/to/Incarnation_Kant
source .venv/bin/activate
Option A — helper script (if paths match your machine)
chmod +x run.sh
./run.sh
Option B — manual (portable)
export STREAMLIT_CONFIG_DIR="$(pwd)/.streamlit"
export HF_HOME="$(pwd)/.venv/.cache/huggingface"
export TORCH_HOME="$(pwd)/.venv/.cache/torch"
export XDG_CACHE_HOME="$(pwd)/.venv/.cache"
mkdir -p logs
streamlit run app/main.py
http://<server-ip>:8501 (open firewall for port 8501 if needed).Bundled
cd /path/to/Incarnation_Kant/neo4j-server
./bin/neo4j-admin server console
System Neo4j
Use your usual systemctl / neo4j commands; ensure Bolt URL matches NEO4J_URI, then start the Streamlit app as above.
| Script / module | Purpose |
|---|---|
initialize.py | Create .venv, install requirements.txt, crawl Korpora to data/raw. |
run.sh | Launch Streamlit with fixed cache env vars; paths may need editing on other machines. |
start_temp_server.sh | Loads .env, starts Streamlit in background to logs/app.log, runs Cloudflare Quick Tunnel (cloudflared); prints a *.trycloudflare.com URL. Requires mkdir -p logs if missing. |
start_online.sh | Requires TUNNEL_TOKEN in .env; runs Streamlit + named Cloudflare tunnel. |
src/database/cleaner.py | HTML → cleaned JSONL. |
src/database/build_chunks.py | Cleaned JSONL → chunk JSONL (LeoLM optional for long sentences). |
src/database/ingest.py | Chunk JSONL → ChromaDB persistent store. |
src/database/build_graph_rag.py | Chunks → Neo4j Graph-RAG (DeepSeek extraction). |
src/database/resolve_entities.py | Offline KNN / SAME_AS edges on concepts in Neo4j. |
src/database/convert_raw.py | Optional raw HTML → line-based TXT (parallel path; not required for the main JSONL pipeline). |
tests/analysis/ — e.g. analyze_chunks.py for chunk quality checks.ModuleNotFoundError: No module named 'src' — run python -m src.database.* from the project root, not from inside src/.app/main.py uses pysqlite3 when available for ChromaDB compatibility..env going forward.Refer to repository LICENSE and NOTICE if present. For technical depth, see report.md.
6 commits
Python
96.3%
TeX
2.0%
A trans-temporal RAG system over Immanuel Kant’s corpus: Streamlit UI, ChromaDB semantic search, and optional Neo4j Graph-RAG. Default platform: Linux. Run all commands from the project root unless noted otherwise.
Prerequisites
torch, chromadb, pydantic).src/Text_2_speech (SadTalker): Linux + ffmpeg in PATH, plus model weights under src/Text_2_speech/checkpoints/.Create the venv and install dependencies
cd /path/to/Incarnation_Kant
# Full init: venv + pip install + crawl Korpora (see section A.4)
python initialize.py
# Or skip crawling and only set up env + deps:
python initialize.py --skip-download
# If you also need Text_2_speech dependencies:
python initialize.py --skip-download --with-text2speech
Activate the virtual environment
source .venv/bin/activate
Secrets
Create a .env file in the project root (do not commit it). At minimum for the web app:
GOOGLE_API_KEY=your_google_generative_ai_key
Optional for Graph-RAG build and Neo4j (see section A.3):
DEEPSEEK_API_KEY=your_deepseek_key
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_neo4j_password
src/config.py loads .env via python-dotenv. Prefer .env for secrets; do not copy API keys into config/settings.yaml (that file may contain placeholders—treat them as non-authoritative).
Non-secret settings
config/settings.yaml — app title, LLM model names, database paths, database.backend (chromadb vs neo4j), etc.database: block (duplicate keys in YAML can be confusing).Config file
.streamlit/config.toml — e.g. port = 8501, address = "0.0.0.0", headless = true.Point Streamlit at the config directory
export STREAMLIT_CONFIG_DIR="$(pwd)/.streamlit"
Caches (recommended)
app/main.py sets Hugging Face and temp dirs under .venv/.cache and .venv/.tmp when you run the app. For manual runs you can mirror run.sh:
export HF_HOME="$(pwd)/.venv/.cache/huggingface"
export TORCH_HOME="$(pwd)/.venv/.cache/torch"
export XDG_CACHE_HOME="$(pwd)/.venv/.cache"
API key
The Streamlit sidebar can set GOOGLE_API_KEY for the session; otherwise the app reads GOOGLE_API_KEY from .env or settings.llm.api_key (see app/main.py).
Known issue: run.sh currently uses hardcoded paths under /Data/Incarnation_Kant/. If you clone elsewhere, either edit run.sh or use manual startup (section B.2) with the exports above.
When you need it
database.backend to chromadb (or omit) — no Neo4j required for basic Q&A.DEEPSEEK_API_KEY for extraction during graph build.Connection
Set NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD in .env (same values can be mirrored under neo4j: in config/settings.yaml for documentation—env wins for overrides in load_config()).
Enable graph retrieval in the app
In config/settings.yaml:
database:
backend: "neo4j"
Bundled Neo4j (this repo)
A community distribution lives under neo4j-server/ (Neo4j 5.26.x). From that directory:
cd neo4j-server
./bin/neo4j-admin server console
bolt://localhost:7687).http://localhost:7474 (first run: set password to match NEO4J_PASSWORD).Pre-built graph store (neo4j-server/data)
The repo does not ship neo4j-server/ (it is gitignored). To use a ready-made Neo4j data directory instead of running build_graph_rag from scratch:
data.zip from Google Drive (sign in if the link requires it).neo4j-server/ — use the same Neo4j 5.x line as the project (see “Bundled Neo4j” above, e.g. 5.26.x). A store built with one minor version may not start on another; align versions with whoever produced the archive.neo4j-server/data/ directory so it does not mix with the archive.neo4j-server/data/ (you should see paths like neo4j-server/data/databases/ and neo4j-server/data/dbms/). If the zip contains a top-level data/ folder, place that folder as neo4j-server/data (not neo4j-server/data/data/).NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD in .env to match the user/password that were set when this database was created (the store on disk is tied to that password). If you only changed the password in the UI after import, use the current password.database.backend: "neo4j" in config/settings.yaml when you want Graph-RAG. The zip only provides the Neo4j graph; ChromaDB under data/chromadb is still built separately by ingest (and may be used as fallback depending on configuration).Alternative: install Neo4j via package manager or use Neo4j Aura; point NEO4J_URI accordingly.
initialize.py crawls korpora.org (Kant section) and writes HTML under data/raw/ (default layout includes data/raw/kant/ for the cleaner).
# Already have venv + deps; only (re)download:
python initialize.py --skip-venv --skip-install
Useful flags: --skip-download, --max-failure-rate, --max-depth (see initialize.py).
Note: After success, initialize.py may still print a legacy hint to scripts/build_database.py. That script does not exist. Use the pipeline in section A.5 instead.
Always run these from the project root with the venv activated.
| Step | Command | Output |
|---|---|---|
| 1. Clean raw HTML → JSONL | python -m src.database.cleaner | data/cleaned/*.jsonl (defaults: --input-dir data/raw/kant, --output-dir data/cleaned) |
| 2. Build semantic chunks | python -m src.database.build_chunks | data/chunks/*.jsonl |
| 3. Build ChromaDB vectors | python -m src.database.ingest | ./data/chromadb (defaults inside ingest.py; uses BGE-M3-style embedding pipeline) |
Optional: Graph-RAG (Neo4j)
Requires running Neo4j, DEEPSEEK_API_KEY, and existing chunks:
python -m src.database.build_graph_rag
python -m src.database.build_graph_rag --limit 20
python -m src.database.build_graph_rag --resume
Optional: entity resolution (SAME_AS edges between concepts)
python -m src.database.resolve_entities
See report.md for parameters, checkpoints, and runtime behavior.
src/Text_2_speech (SadTalker)src/Text_2_speech is an optional talking-head / text-to-speech module. It is independent from the default RAG pipeline.
Environment requirements
.venv) is supported.ffmpeg must be available from command line.src/Text_2_speech/checkpoints/ (required by src/Text_2_speech/inference.py and src/Text_2_speech/src/utils/init_path.py).Install dependencies
# from project root
source .venv/bin/activate
pip install -r requirements-text2speech.txt
Or use initializer:
python initialize.py --skip-download --with-text2speech
Compute requirements (practical guidance)
gfpgan / RestoreFormer).Run quick demo
python src/Text_2_speech/scripts/quick_demo_main.py \
--driven-audio /path/to/audio.wav \
--source-image /path/to/image.png \
--result-dir ./src/Text_2_speech/results \
--preprocess full \
--enhancer gfpgan
If examples/source_image does not exist in your local copy, always pass --source-image explicitly.
Streamlit integration (app/main.py)
500px-Immanuel_Kant_-_Gemaelde_1.jpg exists in the project root, it is used first. Otherwise the first request may download into data/assets/kant_portrait.* (Wikipedia HTML URLs are handled via og:image). Later runs use local files only.pip install -r requirements-text2speech.txt (includes Coqui TTS).cd /path/to/Incarnation_Kant
source .venv/bin/activate
Option A — helper script (if paths match your machine)
chmod +x run.sh
./run.sh
Option B — manual (portable)
export STREAMLIT_CONFIG_DIR="$(pwd)/.streamlit"
export HF_HOME="$(pwd)/.venv/.cache/huggingface"
export TORCH_HOME="$(pwd)/.venv/.cache/torch"
export XDG_CACHE_HOME="$(pwd)/.venv/.cache"
mkdir -p logs
streamlit run app/main.py
http://<server-ip>:8501 (open firewall for port 8501 if needed).Bundled
cd /path/to/Incarnation_Kant/neo4j-server
./bin/neo4j-admin server console
System Neo4j
Use your usual systemctl / neo4j commands; ensure Bolt URL matches NEO4J_URI, then start the Streamlit app as above.
| Script / module | Purpose |
|---|---|
initialize.py | Create .venv, install requirements.txt, crawl Korpora to data/raw. |
run.sh | Launch Streamlit with fixed cache env vars; paths may need editing on other machines. |
start_temp_server.sh | Loads .env, starts Streamlit in background to logs/app.log, runs Cloudflare Quick Tunnel (cloudflared); prints a *.trycloudflare.com URL. Requires mkdir -p logs if missing. |
start_online.sh | Requires TUNNEL_TOKEN in .env; runs Streamlit + named Cloudflare tunnel. |
src/database/cleaner.py | HTML → cleaned JSONL. |
src/database/build_chunks.py | Cleaned JSONL → chunk JSONL (LeoLM optional for long sentences). |
src/database/ingest.py | Chunk JSONL → ChromaDB persistent store. |
src/database/build_graph_rag.py | Chunks → Neo4j Graph-RAG (DeepSeek extraction). |
src/database/resolve_entities.py | Offline KNN / SAME_AS edges on concepts in Neo4j. |
src/database/convert_raw.py | Optional raw HTML → line-based TXT (parallel path; not required for the main JSONL pipeline). |
tests/analysis/ — e.g. analyze_chunks.py for chunk quality checks.ModuleNotFoundError: No module named 'src' — run python -m src.database.* from the project root, not from inside src/.app/main.py uses pysqlite3 when available for ChromaDB compatibility..env going forward.Refer to repository LICENSE and NOTICE if present. For technical depth, see report.md.
6 commits
Python
96.3%
TeX
2.0%