← กลับไปที่รายการ

แนวทางปฏิบัติที่ดีที่สุดของ RAG

สถาปัตยกรรมโดยรวม

  1. คำนวณเอกสารและเวกเตอร์แบบสอบถามด้วย openai/text-embedding-3-large
  2. ดึงข้อมูล Top-K จากร้านค้าเวกเตอร์ (FAISS / Milvus / pgvector)
  3. ขึ้นอันดับใหม่ด้วย cohere/rerank-english-v3
  4. ต่อชิ้นส่วน Top-N เข้ากับพรอมต์แล้วปล่อย cohere/command-r-plus หรือ Claude สร้างคำตอบสุดท้าย

การฝัง

python
resp = client.embeddings.create(
    model="openai/text-embedding-3-large",
    input=[chunk.text for chunk in chunks],
)
vectors = [d.embedding for d in resp.data]

เทมเพลตพร้อมท์

text
You are an expert assistant. Answer based ONLY on context.
If the answer is not in the context, say "I don't know".

[Context]
{retrieved_chunks}

[Question]
{user_question}