Show a desktop notification when the AI TA finishes replying
Notify me when classmates post messages in the forum
Play an alert sound whenever there is a new notification
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.
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:
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.
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.
The message must undergo the following pre-processing steps before embedding:
cl100k_base tokenizer to count tokens; messages over 8,000 tokens will be truncated (and marked was_truncated = 1)| Parameter | Value | Description |
|---|---|---|
| Model | text-embedding-3-small | OpenAI embedding model |
| Vector dimension | 1536 | Output floating-point vector length |
| Tokenizer | cl100k_base | Shared GPT-4 / embedding |
| Maximum Token | 8,000 | Truncate when exceeded |
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:
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.
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||)
Search supports three range filters, and you can narrow the search scope according to research needs:
| Selection scope | Description | Applicable scenarios |
|---|---|---|
| Classroom | Restrict all conversations for a specific Course | Search the whole class's questions |
| User | Conversations restricted to specific Students | Track each Student's cognitive trajectory |
| Chat | Restricted to a specific thread | Search within a single conversation for context |
| Parameter | Default value | Scope | Description |
|---|---|---|---|
top_k | 10 | 1 ~ 50 | Return the top k most similar results |
threshold | 0.3 | 0.0 ~ 1.0 | Minimum similarity threshold; results below this value will be filtered out |
To improve search performance, the system maintains a set of in-memory cache entries for each scope key, with the following cache policy:
| Parameter | Value | Description |
|---|---|---|
| Embedding Model | text-embedding-3-small | OpenAI embedding model |
| Vector dimension | 1536 | Length of the floating-point vector produced by each message |
| Shortest message length | 2 characters | Messages shorter than this are not embedded |
| Maximum number of Tokens | 8,000 | Truncate when exceeded (cl100k_base) |
| Content Hash | MD5 | For content deduplication |
| Real-time embedding | daemon thread | Each new message triggers a background thread |
| Batch Workers | 3 | Partition by log_id % 3 |
| Batch polling interval | 15 seconds | Polling interval for each worker |
| Batch size | 50 records | Maximum number of messages processed per poll |
| Search top_k | 10 (maximum 50) | Default number of returned items |
| Search threshold | 0.3 | Minimum cosine similarity |
| Cache TTL | 5 minutes | per scope key |
| Writing strategy | INSERT IGNORE | Idempotency guarantee |
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.
log_id % 3 to avoid duplicate processingThe 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.
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.
Embedding results are stored in the chat_message_embeddings table:
| Field | Style | Description |
|---|---|---|
id | INT AUTO_INCREMENT PK | Primary key |
log_id | INT, UNIQUE KEY | Corresponding message ID in chat_log |
embedding | BLOB | 1536-dimensional floating-point vector (binary format) |
content_hash | CHAR(32) | MD5 content hash, used for deduplication |
content_preview | VARCHAR(200) | Preview of the first 200 characters of the message |
token_count | INT | Number of tokens in the message |
was_truncated | TINYINT(1) | Whether it has been truncated (0/1) |
created_at | DATETIME | Embedding time |
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.
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.
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: