Skip to content

feat(backend): AGI tutor RAG pipeline over course content (#406) - #482

Open
Degentle12 wants to merge 1 commit into
AetherEdu:mainfrom
Degentle12:feat/issue-406-rag-pipeline
Open

feat(backend): AGI tutor RAG pipeline over course content (#406)#482
Degentle12 wants to merge 1 commit into
AetherEdu:mainfrom
Degentle12:feat/issue-406-rag-pipeline

Conversation

@Degentle12

Copy link
Copy Markdown
Contributor

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.tsQdrantVectorStore (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 when OPENAI_API_KEY is 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)

  • Started on server boot (fails open if the vector store is unreachable); embeds and upserts course chunks idempotently, skipping re-indexing when content is unchanged.

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

  • Course material indexed into a vector store
  • Queries retrieve relevant context before generation
  • Answers include citations to source material
  • Grounding/faithfulness metrics tracked
  • Fallback to a safe "I don't know" when confidence is low

Verification

  • npm run build -w backend passes (tsc, strict mode).
  • ESLint clean on all new/modified files.
  • New test suite passes: npx jest src/__tests__/ragPipeline.test.ts.
  • OpenAPI spec generation + swagger-parser validation passes with the new routes.
  • docker-compose.yml parses with the new qdrant service.

Closes #406

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] AGI tutor RAG pipeline over course content

1 participant