← リストに戻る

RAG 実践ガイド

全体的なアーキテクチャ

  1. ドキュメントとクエリのベクトルを計算します。 openai/text-embedding-3-large
  2. ベクター ストアから Top-K を取得 (FAISS / Milvus / pgvector)
  3. 再ランク付け cohere/rerank-english-v3
  4. 上位 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}