Spaces:
Sleeping
Sleeping
Commit
·
4749f94
1
Parent(s):
c509b44
update the readme.md files
Browse files- README.md +23 -0
- backend/README.md +79 -16
README.md
CHANGED
|
@@ -177,6 +177,29 @@ All calls are proxied through the FastAPI backend running at `http://localhost:8
|
|
| 177 |
|
| 178 |
---
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
## Demo Video
|
| 181 |
|
| 182 |
🎥 **[Demo Video Placeholder]** - Coming soon!
|
|
|
|
| 177 |
|
| 178 |
---
|
| 179 |
|
| 180 |
+
## Testing & Diagnostics
|
| 181 |
+
|
| 182 |
+
IntegraChat ships with several helper scripts to validate the full stack end-to-end:
|
| 183 |
+
|
| 184 |
+
- `python verify_tenant_isolation.py`
|
| 185 |
+
Runs a comprehensive suite that covers analytics logging, admin rule storage, API reachability, and—most importantly—multi-tenant RAG isolation.
|
| 186 |
+
- ✅ **Prerequisites:** FastAPI backend plus all MCP servers (RAG/Web/Admin) running locally.
|
| 187 |
+
- ✅ **What it checks:**
|
| 188 |
+
1. Direct database writes via the analytics and rules stores
|
| 189 |
+
2. CRUD over the `/admin/*` and `/analytics/*` endpoints
|
| 190 |
+
3. RAG ingestion and isolation by issuing queries as multiple tenants and ensuring secrets never leak across IDs
|
| 191 |
+
- ✅ **Pass criteria:** At least 80 % of the sub-tests succeed (the RAG isolation test must pass for overall success).
|
| 192 |
+
|
| 193 |
+
- `python check_rag_database.py`
|
| 194 |
+
Provides a low-level inspection of the RAG datastore. It connects straight to the pgvector/Postgres instance, lists all tenant IDs, prints sample chunks, and runs `search_vectors()` directly to ensure the SQL `WHERE tenant_id = …` filter is behaving as expected. Use this script when diagnosing suspected cross-tenant leakage or when seeding demo data.
|
| 195 |
+
|
| 196 |
+
- `python test_manual.py`
|
| 197 |
+
The existing manual test runner remains useful for smoke-testing analytics logging, admin rule CRUD, and API response codes. Run it whenever you adjust schemas or update MCP endpoints.
|
| 198 |
+
|
| 199 |
+
> **Tip:** All scripts assume the Python virtual environment is active (`source venv/bin/activate` or `.\venv\Scripts\activate`) and that `.env` contains the MCP server URLs/LLM settings noted earlier.
|
| 200 |
+
|
| 201 |
+
---
|
| 202 |
+
|
| 203 |
## Demo Video
|
| 204 |
|
| 205 |
🎥 **[Demo Video Placeholder]** - Coming soon!
|
backend/README.md
CHANGED
|
@@ -1,28 +1,91 @@
|
|
| 1 |
# Backend Documentation
|
| 2 |
|
| 3 |
-
This
|
| 4 |
|
| 5 |
-
##
|
| 6 |
|
| 7 |
-
- `api/`
|
| 8 |
-
- `mcp_servers/` - MCP
|
| 9 |
-
- `
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
##
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
- Headers: `x-tenant-id: <tenant-id>`
|
| 21 |
-
- Body: `{ "message": "<text>" }`
|
| 22 |
-
- Response: `{ "response": "<agent-response>" }`
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
| 1 |
# Backend Documentation
|
| 2 |
|
| 3 |
+
This folder contains the production-ready FastAPI stack plus the companion MCP servers that power IntegraChat.
|
| 4 |
|
| 5 |
+
## Directory Overview
|
| 6 |
|
| 7 |
+
- `api/` – FastAPI application (routes, services, storage helpers, MCP clients)
|
| 8 |
+
- `mcp_servers/` – Stand-alone MCP servers:
|
| 9 |
+
- `rag_server.py` / `main.py` – pgvector-backed retrieval over tenant documents
|
| 10 |
+
- `web_server.py` – DuckDuckGo-powered search with English bias
|
| 11 |
+
- `admin_server.py` – Governance utilities (regex rules, violation logging, tenant registry)
|
| 12 |
+
- `workers/` – Celery workers and schedulers for async ingestion + analytics maintenance
|
| 13 |
|
| 14 |
+
## Prerequisites
|
| 15 |
|
| 16 |
+
- Python 3.10+
|
| 17 |
+
- PostgreSQL (with the `vector` extension) for RAG data, or Supabase with pgvector enabled
|
| 18 |
+
- SQLite (auto-created in `data/`) for analytics and admin rules
|
| 19 |
+
- Optional: Ollama running locally (default) or Groq API credentials for remote LLMs
|
| 20 |
|
| 21 |
+
Create a virtual environment at the repo root, then:
|
| 22 |
|
| 23 |
+
```bash
|
| 24 |
+
pip install -r requirements.txt
|
| 25 |
+
cp env.example .env # update MCP URLs + LLM settings
|
| 26 |
+
```
|
| 27 |
|
| 28 |
+
## Running the Services Locally
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
1. **FastAPI core**
|
| 31 |
+
```bash
|
| 32 |
+
uvicorn backend.api.main:app --port 8000 --reload
|
| 33 |
+
```
|
| 34 |
|
| 35 |
+
2. **MCP servers** (each in its own shell):
|
| 36 |
+
```bash
|
| 37 |
+
# RAG / knowledge base
|
| 38 |
+
python -m backend.mcp_servers.main # or python -m backend.mcp_servers.rag_server
|
| 39 |
+
|
| 40 |
+
# Web search
|
| 41 |
+
python -m backend.mcp_servers.web_server
|
| 42 |
+
|
| 43 |
+
# Admin / governance
|
| 44 |
+
python -m backend.mcp_servers.admin_server
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
3. **Optional workers** (if running Celery-based ingestion/analytics jobs):
|
| 48 |
+
```bash
|
| 49 |
+
celery -A backend.workers.ingestion_worker worker --loglevel=info
|
| 50 |
+
celery -A backend.workers.analytics_worker worker --loglevel=info
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
The Gradio UI (`python app.py`) and the Next.js operator console (see `frontend/README.md`) both talk to the FastAPI layer at `http://localhost:8000`.
|
| 54 |
+
|
| 55 |
+
## Key Endpoints
|
| 56 |
+
|
| 57 |
+
All endpoints require the `x-tenant-id` header unless otherwise noted.
|
| 58 |
+
|
| 59 |
+
| Service | Path | Notes |
|
| 60 |
+
| --- | --- | --- |
|
| 61 |
+
| Agent | `POST /agent/message` | Autonomous orchestration (RAG/Web/Admin/LLM) |
|
| 62 |
+
| Agent Debug | `POST /agent/debug` | Full reasoning trace + tool plan |
|
| 63 |
+
| Agent Plan | `POST /agent/plan` | Dry-run planning without executing tools |
|
| 64 |
+
| RAG | `POST /rag/ingest-document` | Rich ingestion (text, URL, metadata) |
|
| 65 |
+
| RAG | `GET /rag/list` | Paginated document listing per tenant |
|
| 66 |
+
| Admin | `POST /admin/rules` | Regex + severity rule ingestion |
|
| 67 |
+
| Analytics | `GET /analytics/overview` | Summary metrics (queries, tokens, red flags) |
|
| 68 |
+
|
| 69 |
+
Refer to the root `README.md` for the complete endpoint tables.
|
| 70 |
+
|
| 71 |
+
## Diagnostics & Tenant Isolation
|
| 72 |
+
|
| 73 |
+
Use the helper scripts in the repo root when validating backend changes:
|
| 74 |
+
|
| 75 |
+
- `python verify_tenant_isolation.py` – Exercises analytics logging, admin rule CRUD, API reachability, and proves RAG tenant isolation by ingesting + querying as multiple tenants.
|
| 76 |
+
- `python check_rag_database.py` – Talks directly to the pgvector database to list tenant IDs, preview stored chunks, and run safeguarded searches via `search_vectors()`. Helpful when troubleshooting suspected cross-tenant leakage.
|
| 77 |
+
- `python test_manual.py` – Legacy manual smoke test harness (analytics store, admin rules, API surface).
|
| 78 |
+
|
| 79 |
+
> **Troubleshooting tip:** If the isolation script reports a failure, first run `check_rag_database.py` to confirm documents are tagged with the correct `tenant_id`, then restart the RAG MCP server so it reloads the updated SQL filtering logic.
|
| 80 |
+
|
| 81 |
+
## Environment Variables (excerpt)
|
| 82 |
+
|
| 83 |
+
Defined in `env.example`:
|
| 84 |
+
|
| 85 |
+
- `RAG_MCP_URL`, `WEB_MCP_URL`, `ADMIN_MCP_URL`
|
| 86 |
+
- `OLLAMA_URL`, `OLLAMA_MODEL` (or `GROQ_API_KEY` + `LLM_BACKEND=groq`)
|
| 87 |
+
- `SUPABASE_URL`, `SUPABASE_SERVICE_KEY` (optional admin integrations)
|
| 88 |
+
- `APP_ENV`, `LOG_LEVEL`, `API_PORT`
|
| 89 |
+
|
| 90 |
+
Update these before starting the servers to ensure the agent can reach every MCP endpoint and LLM runtime.
|
| 91 |
|