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

6

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

Chat Embedding
semantic vector methodology

Explain how Uedu vectorises dialogue messages between Students and the AI TA, using semantic search and similarity matching to support conversation history retrieval, similar-question detection, and research clustering analysis.

1. Overview

Chat Embedding is Uedu's dialogue semantic vectorisation module, forming the infrastructure for the Cognomics (cognitive process) and Linguomics (language expression) dimensions within the Educational Omics framework.

The system will convert each message (request) sent by Students to the AI TA into a high-dimensional semantic vector and store it in the database. These vectors can be used for:

  • Semantic search: perform semantic retrieval in the conversation history using natural language, replacing traditional keyword search
  • Similar question detection: identify semantically similar questions raised by different Students to help Instructors understand learning pain points
  • Research clustering analysis: analyse Students' question patterns and cognitive trajectories through distributions in vector space
Relationship to RAG

Chat Embedding reuses the embedding infrastructure of the RAG (teaching material retrieval augmentation) module, including the same model (text-embedding-3-small) and vector dimensions (1536 dimensions). RAG embeds teaching material chunks; Chat Embedding embeds student dialogue messages.

2. Vectorisation workflow

2.1 Embedded object

The system only embeds the messages sent by Students (request), and does not embed the AI's replies (response). This is because the research focuses on Students' questioning behaviour and cognitive expression, rather than the AI's output.

2.2 Text pre-processing

The message must undergo the following pre-processing steps before embedding:

  1. Cleaning: Remove extraneous whitespace and formatting noise
  2. Minimum length check: messages must contain at least 2 characters; messages that are too short (e.g. a single punctuation mark) will be skipped
  3. Token truncation: uses the cl100k_base tokenizer to count tokens; messages over 8,000 tokens will be truncated (and marked was_truncated = 1)
  4. Content hash: calculate a MD5 content hash for deduplication to avoid embedding identical content repeatedly

2.3 Embedding model

ParameterValueDescription
Modeltext-embedding-3-smallOpenAI embedding model
Vector dimension1536Output floating-point vector length
Tokenizercl100k_baseShared GPT-4 / embedding
Maximum Token8,000Truncate when exceeded

2.4 Dual-path processing

The system adopts a dual-path architecture of real-time + batch backfill, ensuring that new messages are vectorised immediately while historical data are also completed:

Chat Embedding two-path architecture Student Messages request to AI chat_log write Real-time embedding embed_message_async daemon thread per message Batch backfill 3 workers · log_id % 3 partition 15-second polling · 50 records per batch Fill in historical unembedded messages chat_message_embeddings log_id (UK) · embedding BLOB content_hash · token_count INSERT IGNORE idempotent write Semantic search cosine similarity in-memory cache

2.5 Skip message handling

Messages that do not meet the embedding criteria (too short, no substantive content) will be written to a NULL embedding record, to prevent the batch backfill process from repeatedly attempting to process them. This ensures each message is evaluated only once.

3. Semantic search mechanism

3.1 Search principle

Semantic search uses cosine similarity to calculate the similarity between the query vector and all embedding vectors in the database. The system uses numpy matrix operations for efficient computation:

similarity = (A · B) / (||A|| × ||B||)

3.2 Scope filtering

Search supports three range filters, and you can narrow the search scope according to research needs:

Selection scopeDescriptionApplicable scenarios
ClassroomRestrict all conversations for a specific CourseSearch the whole class's questions
UserConversations restricted to specific StudentsTrack each Student's cognitive trajectory
ChatRestricted to a specific threadSearch within a single conversation for context

3.3 Search parameters

ParameterDefault valueScopeDescription
top_k101 ~ 50Return the top k most similar results
threshold0.30.0 ~ 1.0Minimum similarity threshold; results below this value will be filtered out

3.4 Memory cache

To improve search performance, the system maintains a set of in-memory cache entries for each scope key, with the following cache policy:

  • TTL: automatically expires after 5 minutes
  • Cache invalidation: when new embeddings are written to that range, the cache is invalidated immediately and reloaded
  • Cached content: includes the vector matrix and corresponding metadata to avoid repeated database queries

4. System parameters

ParameterValueDescription
Embedding Modeltext-embedding-3-smallOpenAI embedding model
Vector dimension1536Length of the floating-point vector produced by each message
Shortest message length2 charactersMessages shorter than this are not embedded
Maximum number of Tokens8,000Truncate when exceeded (cl100k_base)
Content HashMD5For content deduplication
Real-time embeddingdaemon threadEach new message triggers a background thread
Batch Workers3Partition by log_id % 3
Batch polling interval15 secondsPolling interval for each worker
Batch size50 recordsMaximum number of messages processed per poll
Search top_k10 (maximum 50)Default number of returned items
Search threshold0.3Minimum cosine similarity
Cache TTL5 minutesper scope key
Writing strategyINSERT IGNOREIdempotency guarantee

5. Batch processing

5.1 Batch backfill architecture

The batch backfill process handles messages missing from real-time embeddings (for example, messages generated during a service restart), as well as historical messages from before the system went live.

  • Number of workers: 3 parallel workers
  • Partition strategy: assign messages to different workers using log_id % 3 to avoid duplicate processing
  • Polling interval: query the database every 15 seconds to obtain messages not yet embedded
  • Batch size: process up to 50 messages at a time

5.2 Idempotency guarantee

The database uses log_id as a UNIQUE KEY, and INSERT IGNORE is used when writing. Even if the real-time path and the batch path process the same message at the same time, duplicate records will not be created.

Why do we need dual pathways?

The real-time path ensures that new messages can be immediately searched semantically after submission, delivering the best user experience. The batch path is responsible for filling in all omissions to ensure data completeness. The two work together via INSERT IGNORE without interfering with each other.

6. Data storage

6.1 Data table structure

Embedding results are stored in the chat_message_embeddings table:

FieldStyleDescription
idINT AUTO_INCREMENT PKPrimary key
log_idINT, UNIQUE KEYCorresponding message ID in chat_log
embeddingBLOB1536-dimensional floating-point vector (binary format)
content_hashCHAR(32)MD5 content hash, used for deduplication
content_previewVARCHAR(200)Preview of the first 200 characters of the message
token_countINTNumber of tokens in the message
was_truncatedTINYINT(1)Whether it has been truncated (0/1)
created_atDATETIMEEmbedding time

6.2 NULL Embedding record

Messages that do not meet the embedding criteria (insufficient length, no substantive content) will be written to a record with embedding = NULL. This allows the batch backfill process to quickly identify unprocessed messages via LEFT JOIN, avoiding repeated attempts.

Storage considerations

Each embedding is 1536 float32 values, using about 6 KB. For a course with 50 students and an average of 200 messages per student, about 60 MB of storage is required. It is recommended to monitor table size regularly.

7. Research citation guidance

Methodology description template

The dialogue content between the Student and the AI TA is semantic-vectorised by the Chat Embedding module on the Uedu platform. The system uses the OpenAI text-embedding-3-small model (1536 dimensions) to convert each Student message (request) into a semantic vector. Text pre-processing includes a minimum length check (2 characters), cl100k_base tokenizer truncation (limit 8,000 tokens), and MD5 content-hash deduplication. The system adopts a dual-path architecture of real-time embedding (daemon thread) and batch backfill (3 workers, log_id % 3 partitioning, 15-second polling, 50 items per batch). Semantic search uses cosine similarity and supports filtering by Course, user and conversation-thread scopes, returning the top 10 similar results by default (threshold 0.3). Embedding results are stored in the chat_message_embeddings table, using INSERT IGNORE to ensure idempotency. See https://uedu.tw/doc/chat-embedding for a detailed methodological explanation.

It is recommended to provide the following:

  • Embedded message types (Student request only or including AI response)
  • Data collection period and number of valid messages
  • Search parameter settings (top_k, threshold)
  • Informed consent form version and IRB approval number
  • If used for clustering analysis, explain the dimensionality reduction and clustering algorithms used