feat(backend): AGI tutor RAG pipeline over course content (#406) - #482
Open
Degentle12 wants to merge 1 commit into
Open
feat(backend): AGI tutor RAG pipeline over course content (#406)#482Degentle12 wants to merge 1 commit into
Degentle12 wants to merge 1 commit into
Conversation
Builds a retrieval-augmented generation pipeline so the AGI tutor answers from indexed course material instead of a static surface: - backend/src/services/tutor/: chunking + deterministic embeddings, a Qdrant vector store (with in-memory fallback for tests), content provider, answer generators (extractive by default, OpenAI-compatible when OPENAI_API_KEY is set) and grounding/faithfulness metrics. - backend/src/workers/indexingJob.ts: content indexing worker, started on server boot, that embeds and upserts course chunks idempotently. - Routes: POST /api/agi-tutor/rag/ask returns grounded answers with inline citations and metrics; POST /api/agi-tutor/rag/index triggers indexing; GET /api/agi-tutor/rag/status reports store state. - Answers fall back to a safe "I don't know" when retrieval or faithfulness confidence is below the configured threshold. - docker-compose.yml: adds a Qdrant vector store container. Closes AetherEdu#406
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the AGI tutor RAG pipeline over course content (#406). The tutor now answers from indexed course material instead of a static surface, with grounded answers, citations, and a safe "I don't know" fallback.
What's included
RAG pipeline (
backend/src/services/tutor/)embeddings.ts— deterministic, keyless embeddings (feature-hashed character n-grams, L2-normalized) so no external embedding API is required.vectorStore.ts—QdrantVectorStore(REST) plus an in-memory fallback used in tests / no-Docker environments.contentProvider.ts— course material provider (chunks seed course content; interface ready for a DB-backed provider).generators.ts— extractive answer generator (default) and an OpenAI-compatible generator used automatically whenOPENAI_API_KEYis set.groundingMetrics.ts— faithfulness (n-gram containment), citation coverage, retrieval confidence, and an overall confidence score.ragPipeline.ts— orchestrates retrieval → generation → citation + grounding metrics → safe fallback when confidence is below threshold.Indexing worker (
backend/src/workers/indexingJob.ts)API
POST /api/agi-tutor/rag/ask— grounded answer with citations and grounding metrics (or the "I don't know" fallback).POST /api/agi-tutor/rag/index— trigger content indexing.GET /api/agi-tutor/rag/status— indexing/vector store status.Infra & config
docker-compose.yml— new Qdrant vector store container.backend/.env.example— RAG/Qdrant/LLM configuration variables.Tests
backend/src/__tests__/ragPipeline.test.ts— 16 tests covering embeddings, retrieval, indexing (including skip-on-unchanged), grounded answers with citations, confidence fallback, and metrics.Acceptance criteria
Verification
npm run build -w backendpasses (tsc, strict mode).npx jest src/__tests__/ragPipeline.test.ts.docker-compose.ymlparses with the newqdrantservice.Closes #406