Initial thoughts
Overview This guide outlines the technical architecture and implementation strategy for integrating a JSON-based model of mental state dynamics into a Retrieval-Augmented Generation (RAG) system, powered by an LLM such as OpenAI or a local model via Ollama. The goal is to support dynamic, meaning-based conversations about mind transitions, especially those described in Buddhist sources such as the Bardo Thödol.
1. Project Structure
rag-project/
├── data/ # Stores uploaded JSON mental-state descriptors
├── chroma_db/ # Vectorstore backed by ChromaDB
├── load_and_embeded.py # Script for embedding and adding JSONs to vectorstore
├── qm.py # OpenAI-based query tool
├── qr.py # Local model (e.g., Ollama) query tool
├── rag_web_service.py # FastAPI-based backend service
├── templates/ # HTML templates for web client
├── static/ # CSS and frontend JS assets
2. JSON Descriptor Model Each file represents a mental state or phase change, e.g.:
{
"id": "earth_dissolution",
"stage": "dissolution",
"element": "earth",
"withdrawal": "solidity and form dissolve",
"bodily_signs": "loss of strength, sinking feeling",
"mental_signs": "scattered thoughts, detachment",
"symbolic_image": "flickering yellow light",
"constraints_released": ["form", "body-attachment"],
"field_effect": "loss of grounding",
"next": "water_dissolution"
}
3. Data Loading and Embedding
- Run
load_and_embeded.py
to embed all files indata/
into ChromaDB using HuggingFace embeddings - Update imports to use
langchain_community.*
as needed - Automatically persists Chroma state
4. Backend Web Service (FastAPI)
- Endpoints:
POST /upload-json
: Upload a JSON file with form dataGET /list-jsons
: List summaries of uploaded JSONsGET /json/{filename}
: View full JSON contentDELETE /json/{filename}
: Delete a JSON descriptor
- Runs via Uvicorn with CORS enabled for cross-site interaction
- Summarizes each descriptor dynamically
5. Web Client Page
- HTML client can be embedded in WordPress or standalone
- Allows upload of JSON mental descriptors
- Lists and previews descriptors via
list-jsons
- Simple RAG query form sends user input to backend
6. Querying
qm.py
: Uses OpenAI LLM to run a RAG query with embedded contextqr.py
: Uses Ollama LLM locally for the same purpose- Both read from ChromaDB
7. Notes on Hosting & Deployment
- Can be served locally or remotely
- Port 8000 may require firewall opening
- RAG system accessible from other servers/sites via FastAPI
- JSON uploads dynamically alter the RAG corpus
Next Steps
- Improve JSON editing pipeline (web-based preview and edit)
- Incorporate long-form source parsing (e.g. full Bardo Thödol)
- Develop “state tracker” that follows evolving awareness states across time
- Design backend support for generating or proposing JSON descriptors from source text
This document provides the technical baseline needed for operationalizing the deeper vision captured in the companion document: Building a Dynamic Model of Mind from Buddhist Descriptions of Mental Transitions.