← Back to list

RAG best practices

Overall architecture

  1. Compute document and query vectors with openai/text-embedding-3-large
  2. Retrieve Top-K from a vector store (FAISS / Milvus / pgvector)
  3. Re-rank with cohere/rerank-english-v3
  4. Stitch the Top-N chunks into the prompt and let cohere/command-r-plus or Claude generate the final answer

Embedding

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]

Prompt template

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}