RAG (Retrieval Augmented Generation): Tăng độ chính xác AI
Lập Trình

RAG (Retrieval Augmented Generation): Tăng độ chính xác AI

Admin Manager
21 tháng 12, 2025
5 phút đọc
0 lượt xem
#NestJS #Lập trình

RAG = Retrieval (Tìm kiếm) + Augmented (Tăng cường) + Generation (Sinh text)

VẤN ĐỀ CỦA LLM THÔNG THƯỜNG

  • Hallucination (bịa đặt)
  • Kiến thức cũ (cutoff date)
  • Không biết data nội bộ công ty

RAG GIẢI QUYẾT NHƯ THẾ NÀO?

Quy trình:

  1. User hỏi: "Chính sách nghỉ phép?"
  2. Tìm kiếm trong database công ty
  3. Lấy top 5 đoạn văn liên quan
  4. Đưa vào context của LLM
  5. LLM trả lời dựa trên context

TECH STACK

  • Vector DB: Pinecone, Weaviate, Chroma
  • Embedding: OpenAI ada-002, Cohere
  • LLM: GPT-4, Claude
  • Framework: LangChain, LlamaIndex

CODE EXAMPLE

from langchain import OpenAI, VectorStore

# 1. Embed documents
vectorstore = VectorStore.from_documents(docs)

# 2. Retrieve
relevant_docs = vectorstore.similarity_search(query)

# 3. Generate
llm = OpenAI()
answer = llm(context=relevant_docs, question=query)

KẾT LUẬN

RAG là must-have cho chatbot doanh nghiệp.

Chia sẻ

Nhận tin mới nhất

Cập nhật AI & Tech hàng tuần

Bài viết liên quan