LOT 1 - Optimizare script build -Instalare mono comanda

This commit is contained in:
Dezvoltari Evotech 2026-06-27 06:42:02 -07:00
parent 5380c3fc63
commit 42ff22bf85
127 changed files with 16163 additions and 532 deletions

View file

@ -23,7 +23,7 @@ HTTP contract but serves responses from a locally-grown **knowledge graph**:
- **Atoms** (documents and atomic claims) are stored in a Postgres +
pgvector backend with multilingual embeddings (BGE-M3, 1024-dim).
- **Claim extraction** runs Qwen 3.5 397B over every ingested document to
- **Claim extraction** runs Qwen3.5 over every ingested document to
pull out verifiable atomic claims with source quotes and stance.
- **Retrieval** uses vector kNN + BGE-reranker-v2-m3 cross-encoder for
precision.
@ -46,9 +46,9 @@ background. Next time a similar claim arrives, it's a HIT.
| **Brain storage** | [Atomic](https://github.com/kenforthewin/atomic) (Rust) on Postgres 16 + pgvector |
| **Embeddings** | `BAAI/bge-m3` via vLLM OpenAI-compat (1024 dim, 8K ctx, multilingual) |
| **Reranker** | `BAAI/bge-reranker-v2-m3` cross-encoder via vllm-rerank-api |
| **LLM (reasoning)** | `Qwen3.5-397B-A17B` (MoE) via llama.cpp through an OpenAI-compat router |
| **LLM (reasoning)** | `qwen3.5` via vLLM through an OpenAI-compat router (`MODEL_FAST` enabled) |
| **Service** | Python 3.12, FastAPI, Uvicorn, Pydantic v2, httpx, structlog, tenacity |
| **Deployment** | Docker + docker-compose (3 services: api, atomic, postgres) |
| **Deployment** | Docker + docker-compose (4 services: api, atomic, postgres, scheduler) |
## Quick start — local dev
@ -88,7 +88,7 @@ curl -fsS http://localhost:8090/health
```
Open the interactive Swagger UI at **http://localhost:8090/docs** to poke
the 5 endpoints live.
the full route set live (~30 routes).
## Production deploy — fresh Linux server
@ -127,6 +127,21 @@ backends safely ignore.
| `POST /v1/gather` | claim → ranked evidence with NLI stance | 5-6 s (1.5 s without NLI) |
| `POST /v1/image-search` | stub (always empty list) | <5 ms |
| `POST /v1/ingest` | populate brain from web-module output | variable (async extraction) |
| `POST /v1/verification_cache` | write claim verification result (claims cache) | <50 ms |
| `POST /v1/analysis_atom/lookup` | read cached analysis result (techniques / ai_tampered / claims) | <50 ms |
| `POST /v1/analysis_atom` | write analysis atom (silver/bronze by confidence) | <50 ms |
| `PATCH /v1/analysis_atom/{id}` | promote atom to gold (moderator review) | <50 ms |
| `GET /v1/analysis_atom/stats` | per-tier/component counts + 24h hit rate | <20 ms |
| `POST /v1/canonicalize` | temporal claim disambiguation (Pilon 7) | LLM-bound |
| `POST /v1/cache/invalidate` | mass invalidation with `dry_run` (Pilon 8) | variable |
| `GET /v1/cache/audit_log` | paginated audit browser | <50 ms |
| `GET/PATCH /v1/fact_status/*` | versioned fact-status layer (list/detail/versions/override) | <50 ms |
This is the full set served by `brain_api` (~30 routes including the FastAPI
auto docs); the `/v1/gather`, `/v1/search`, `/v1/fetch`, `/v1/ingest`,
`/v1/image-search` group is the web-gathering contract, the rest are the
brain-owned cache + freshness-defense layers. See `INDEX.md` for the
canonical route list.
The response from `/v1/gather` matches the existing web-module shape
exactly plus an additive `brain_meta` object on the top level and inside
@ -156,11 +171,11 @@ Didi backend
│ stage context → language detection │
│ stage retrieval → Atomic semantic search (top 50) │
│ stage rerank → BGE cross-encoder (top 15) │
│ stage nli → Qwen 397B stance vs query
│ stage nli → Qwen3.5 stance vs query
│ stage evidence → group by parent doc, shape │
└──────┬──────────────────────────┬──────────────────┘
│ │
│ HTTP (docker DNS) │ HTTPS (VPN)
│ HTTP (docker DNS) │ HTTP (docker DNS)
▼ ▼
┌────────────────┐ ┌───────────────────────┐
│ atomic-server │ │ BGE-M3 embeddings │
@ -169,9 +184,9 @@ Didi backend
│ └───────────────────────┘
┌────────────────┐ ┌───────────────────────┐
│ postgres │ │ Qwen 3.5 397B-A17B
│ postgres │ │ qwen3.5
│ + pgvector │ │ via LLM router │
│ :5432 (5434) │ │ (llama.cpp + vLLM)
│ :5432 (5434) │ │ (vLLM)
└────────────────┘ └───────────────────────┘
```
@ -179,7 +194,7 @@ Didi backend
```
didibrain/
├── infra/docker-compose.yml # 3-service stack
├── infra/docker-compose.yml # 4-service stack (api, atomic, postgres, scheduler)
├── brain_api/ # FastAPI service (the main deliverable)
├── shared/ # config, clients, taxonomy (reused everywhere)
├── extractor/ # claim extraction (host jobs + /v1/ingest)
@ -201,7 +216,7 @@ Detailed file-by-file rundown is in `STATUS.md`.
- [x] Claim extraction (513 atoms, 1.2% hallucination filter)
- [x] Document-level retrieval validated (cross-lingual cosine 0.88-0.94)
- [x] Claim-level retrieval validated
- [x] brain_api HTTP service with Didi contract (5 endpoints)
- [x] brain_api HTTP service with Didi contract (full route set, ~30 routes)
- [x] brain_api dockerized (self-sufficient, taxonomy auto-refresh)
- [x] NLI stance vs query in `/v1/gather`
- [x] Lint pass contradiction detection (code + smoke test)
@ -213,16 +228,20 @@ Detailed file-by-file rundown is in `STATUS.md`.
## Operational notes
- **Resource footprint**: ~200 MB RAM total across the 3 containers; brain-api
- **Resource footprint**: ~200 MB RAM total across the 4 containers; brain-api
idles at ~6% CPU, spikes to ~20% during a `/v1/gather` with NLI.
- **Image size**: brain-api Docker image is ~253 MB (Python 3.12-slim base).
- **VPN dependency**: BGE and the LLM router live on a VPN-routed 10.11.10.x
network. If the VPN drops, `/v1/gather` returns 500 because Atomic cannot
embed the query. Confirm upstream reachability before debugging anything
else when search starts failing.
- **Self-sufficient startup**: brain_api pulls the current taxonomy from
Atomic at startup, so there is no baked `_tag_ids.json` in the image and
the container is portable across environments.
- **Upstream connectivity**: the LLM router, BGE-M3 embeddings, and the BGE
reranker are reached over Docker DNS as `didiAI-llm-api:14011`,
`didiAI-embeddings-api:14100`, and `didiAI-rerank-api:14200` on the shared
`didi-network`. If those upstreams are unreachable, `/v1/gather` returns 500
because Atomic cannot embed the query. Confirm upstream reachability before
debugging anything else when search starts failing.
- **Startup**: brain_api refreshes the `TagResolver` from Atomic at startup;
in addition `shared/_tag_ids.json` is mounted into the container (compose
volume) so background extraction — which instantiates `TagResolver`
directly, bypassing the lifespan refresh — can still resolve canonical tag
UUIDs.
- **Idempotency**: every operator script (taxonomy seeder, Wikipedia
importer, claim extractor, Lint pass) is idempotent via state files or
URL-based dedup. Re-running is always safe.