Files
heala-backend/docs/rag-plan.md
T
2026-11-27 20:46:29 +03:30

2.8 KiB

RAG implementation milestones

Milestone Main files Verification
1. Audit Existing NestJS, Redis, JWT, TypeORM, OpenRouter and chat modules Reused the existing API, response envelope, roles and provider client
2. Vector storage src/migrations, article entities, vector.repository.ts Created the schema and HNSW index, wrote TypeORM vectors and checked cosine search and model filtering against pgvector via a disposable PGlite socket
3. CPU service embedding-service, embedding.provider.ts Verified API validation, E5 prefixes, batch encoding and 384-dimensional normalized output with the pinned CPU model
4. Ingestion articles.controller.ts, document parser, ingestion worker Verified HTTP role checks and file validation, PDF pages, DOCX headings, TXT normalization, queue options, retry transitions and stale worker fencing
5. Retrieval rag-retrieval.service.ts, rag-context.service.ts, rag-generation.service.ts Verified thresholds, deduplication, prompt budgets, missing-evidence handling, untrusted excerpts and citation validation
6. Chatbot Existing chatbot and conversation modules, citation migration Verified the legacy response, grounded SSE event, history and citation snapshots, with OpenRouter mocked
7. Operations Compose, Dockerfiles, .env.example, runbook Verified build, lint, typecheck, Jest, Python and Compose configuration. Docker Hub returned HTTP 403 for the required images

The existing Compose deployment uses PostgreSQL major 17. TypeORM has native vector support. The old HTTP test targeted a root route absent from the application and lacked path alias configuration. A multipart upload test now exercises the real JWT guard and application response envelope.

Verification commands

  • npm test -- --runInBand passed 53 tests. The optional integration case passed separately with PGVECTOR_TEST_URL and npm test -- --runInBand pgvector.spec.
  • npm run test:e2e -- --runInBand passed three HTTP tests.
  • npx tsc --noEmit --incremental false, npx eslint "src/**/*.ts" "test/**/*.ts" and npm run build passed.
  • python -m pytest -q embedding-service passed four cases with RAG_REAL_MODEL_TEST=1, including CPU inference using the pinned E5 weights.
  • docker compose --env-file .env.example --profile rag config --quiet passed with APP_ENV_FILE=.env.example.

Before rollout, run the full Compose stack on a host with registry access and smoke-test upload, Redis processing, grounded chat and fallback on an approved corpus. The local checks used a disposable vector database and mocked the generation provider.

npm audit --omit=dev reported the same production advisory counts for both lockfiles. Review the existing 14 high and one critical advisories before deployment.