National Chengchi University
Uedu Main Site
Explore Uedu
Student Console
Register as Member/Login
Research Informed Consent Center
Survey Center
Teacher Console
Course Setup
Support & Messages
Uptime Data

UeduGPTs

--

Jupyters

7

Local AI

--

Uedu Code

--

AI Reply Desktop Notifications

Show a desktop notification when the AI TA finishes replying

Chat Message Notifications

Notify me when classmates post messages in the forum

Sound notification

Play an alert sound whenever there is a new notification

METHODOLOGY

RAG Teaching Material Retrieval-Augmented
Methodology

Explain how Uedu uses Retrieval-Augmented Generation (RAG) to ensure the AI TA's replies are grounded in teaching materials uploaded by Instructors, improving answer accuracy and teaching relevance.

1. Overview

The AI teaching assistants (UeduGPTs) on the Uedu platform support the AI knowledge base function: Instructors upload Course materials (PDF, DOCX, PPTX), and the system automatically chunks and vectorises the materials. When students ask questions, it performs semantic retrieval and injects the most relevant material excerpts into the AI's System Prompt so that the AI's replies can be grounded in the Course materials.

This mechanism is known as RAG (Retrieval-Augmented Generation), which is the current mainstream method used in the industry to enable LLMs to answer with evidence. This document explains the implementation details of Uedu's RAG for researchers to understand the data generation process.

2. What is RAG

RAG (Retrieval-Augmented Generation) is an architecture that combines information retrieval and text generation (Lewis et al., 2020). Its core concept is:

  1. Retrieval: when the user asks a question, first find the most relevant document excerpts from the knowledge base
  2. Augmentation: inject retrieved passages into the LLM input as additional context
  3. Generation: LLM generates answers based on the original question + retrieved teaching materials

Compared with answers that rely only on an LLM’s built-in knowledge, RAG allows AI replies to be grounded in specific teaching materials, reducing the risk of hallucination and ensuring the content remains relevant to the Course.

3. Data processing workflow

After the Teacher uploads course materials, the system carries out the following processing steps in the background:

RAG data processing pipeline Teachers upload teaching materials (PDF / DOCX / PPTX) Step 1: Text extraction pypdf / python-docx / python-pptx full-text extraction Retain page numbers / slide numbers Step 2: Semantic chunking (Chunking) tokenizer: cl100k_base (tiktoken) max_tokens=800, overlap=100, min_tokens=20 Adjacent chunks overlap by 100 tokens to avoid semantic breaks at the boundaries Step 3: Vector embeddings (Embedding) model: text-embedding-3-small, 1536 dimensions Batch processing, 20 chunks per batch Step 4: Save to database rag_chunks table: content + embedding (BLOB) + page number + token count Step 5: Load memory cache numpy matrix cache (TTL 5 minutes), speeding up subsequent retrievals Option: auto-trigger Knowledge Graph generation (GraphRAG mode) Materials ready, waiting for student questions

3.1 Text extraction

The system supports three file formats, and uses the corresponding Python packages to extract the full text:

FormatExtraction toolPage tracking
PDFpypdfRetain original page numbers
DOCXpython-docxNo page numbers (paragraphs merged)
PPTXpython-pptxRetain slide numbers

3.2 Semantic chunking (Chunking)

The extracted full text is tokenised into chunks at token level using the tiktoken cl100k_base tokenizer:

  • Maximum chunk length: 800 tokens
  • Adjacent chunk overlap: 100 tokens — ensure the semantics across chunk boundaries do not break
  • Minimum chunk length: 20 tokens — chunks that are too short will be discarded

Chunking is carried out page by page (or slide by slide). If the text on a single page is no more than 800 tokens, treat the page as one whole chunk; otherwise, use token-level sliding segmentation.

3.3 Vector embedding (Embedding)

The text of each chunk is converted by OpenAI text-embedding-3-small into a 1536-dimensional dense vector, stored in the database BLOB field as float32.

4. Semantic retrieval mechanism

When a student submits a question, the system carries out the following retrieval steps before replying:

  1. Convert the Student's question text into a 1,536-dimensional vector using the same embedding model (text-embedding-3-small)
  2. Load the embedding matrix for all chunks in this Course from memory cache (cache TTL 5 minutes)
  3. Compute cosine similarity between the question vector and all chunk vectors
  4. Retrieve the top-k chunks with the highest similarity, filtering out results below the threshold
  5. Format the retrieved teaching material excerpts and inject them into the AI's System Prompt
Cosine Similarity

Cosine similarity measures the degree of directional closeness between two vectors, with a range of [-1, 1]. In embedding space, texts with similar meanings will have higher similarity scores. The system uses numpy for efficient matrix operations.

5. System parameters

ParameterValueDescription
EMBEDDING_MODELtext-embedding-3-smallOpenAI embedding model
EMBEDDING_DIMENSIONS1536Vector dimension
CHUNK_MAX_TOKENS800Maximum token count per chunk
CHUNK_OVERLAP_TOKENS100Number of overlapping tokens between adjacent chunks
CHUNK_MIN_TOKENS20Minimum chunk length (discard if below this value)
RETRIEVAL_TOP_K3Maximum number of chunks returned per retrieval
RETRIEVAL_THRESHOLD0.3Minimum cosine similarity threshold
CACHE_TTL300 secondsMemory cache retention time

6. GraphRAG expansion

Uedu supports advanced GraphRAG mode. When the Instructor turns on this mode, the system will not only use standard vector retrieval, but will also useKnowledge graphProceedGraph expansion retrieval

  1. Standard vector retrieval hits several chunks
  2. Query the knowledge concepts corresponding to these chunks (kg_concepts)
  3. Use the relation edges in the knowledge graph (1-hop) to find adjacent concepts
  4. Supplement the retrieval results with teaching material chunks from adjacent concepts (up to 3 extra)

When expanding the graph, the edge weights for prerequisite (prior knowledge) and contains (containment relationship) will receive a 1.2x boost, and teaching materials for these two types of links will be prioritised.

Standard RAG vs. GraphRAG

Standard RAG relies only on vector-similarity retrieval, and may miss teaching materials that are not directly similar in meaning but are conceptually related. GraphRAG supplements these fragments through structured links in the knowledge graph, improving the completeness of answers.

7. Retrieval logs and transparency

Detailed logs for each retrieval are stored in the rag_retrieval_log table, including:

  • query_text: the Student's original question
  • chunk_ids: array of chunk IDs matched by retrieval
  • similarity_scores: corresponding cosine similarity scores
  • retrieval_time_ms: retrieval time (milliseconds)

These records allow researchers to analyse “which textbook segments AI referred to when answering” and “the degree of semantic match between Student questions and the teaching materials”.

8. Suggested research citation

Methodology description template

The AI Teaching Assistant’s replies are grounded in teacher-uploaded materials via Retrieval-Augmented Generation (RAG; Lewis et al., 2020). After text extraction, material files (PDF/DOCX/PPTX) are semantically chunked with the tiktoken cl100k_base tokenizer (up to 800 tokens per chunk, with 100 tokens overlap between adjacent chunks), then converted by the OpenAI text-embedding-3-small model into 1,536-dimensional dense vectors. When a Student asks a question, the system retrieves the most semantically relevant material passages using cosine similarity (top-3, threshold 0.3) and injects them into the AI System Prompt as the basis for its reply. Each retrieval record (matched passages, similarity scores) is retained for research analysis. See the detailed methodology at https://uedu.tw/doc/rag.

It is recommended to add the following information as a note as well:

  • The Course uses standard RAG or GraphRAG mode
  • Number of uploaded course materials and total token count (viewable from the Instructor side)
  • embedding model name and version