/ RAG Basics

Embedding và Semantic Search

Giải thích cách văn bản trở thành vector, cosine similarity và một bài thực hành semantic search tiếng Việt chạy cục bộ.An explanation of text embeddings, cosine similarity, and a local Vietnamese semantic-search exercise.

embeddingsemantic-searchcosine-similarityrag

Nguồn tham khảo: Phạm Thành Thái - AI Guru x TiniXReference source: Phạm Thành Thái - AI Guru x TiniX

Tổng quan

Tài liệu nối tiếp bài chunking bằng cách biến từng đoạn thành vector và đo độ gần ngữ nghĩa. Phần thực hành sử dụng sentence-transformers cùng mô hình tiếng Việt để nhúng một tập đoạn văn, chuẩn hóa vector và truy vấn bằng cosine similarity mà không phụ thuộc API trả phí.

Điểm chính

  • Embedding model và mô hình sinh văn bản đảm nhiệm hai vai trò khác nhau.
  • Cosine similarity đo hướng của vector; chuẩn hóa giúp truy vấn bằng dot product hiệu quả.
  • Model, dimension và cách tiền xử lý phải thống nhất giữa lúc lập chỉ mục và truy vấn.
  • Semantic search vẫn cần metadata, chunking và đánh giá retrieval để tạo thành RAG hoàn chỉnh.

Ghi chú của mình

Bài học quan trọng là chọn model theo ngôn ngữ và dữ liệu thật, sau đó cố định version để tránh lệch vector giữa các lần index.

Overview

The document continues from chunking by turning passages into vectors and measuring semantic proximity. Its exercise uses sentence-transformers and a Vietnamese model to embed passages, normalize vectors, and query with cosine similarity without a paid API.

Key points

  • Embedding and generation models serve different roles.
  • Cosine similarity compares vector direction; normalization enables efficient dot-product search.
  • Model, dimensions, and preprocessing must remain consistent between indexing and querying.
  • Semantic search still needs metadata, chunking, and retrieval evaluation to form a complete RAG system.

My notes

The key lesson is to choose models against the real language and data, then pin versions to avoid embedding drift across indexing runs.