StudyVisuallyStart studying
AI developers · Part 05

Embeddings + RAG

Turn text into vectors, search them, and ground answers in your own data.

Last updated

  1. EmbeddingA list of numbers (a vector, often 384 or 1536 long) that captures the meaning of a piece of text. Similar meanings get similar numbers.
  2. Cosine similarityA score of how close two embeddings are in meaning. 1 means the same meaning, 0 means unrelated.
  3. Semantic searchSearch by meaning instead of exact words. It finds "rollback steps" when you asked about reverting a deploy.
  4. Vector databaseA database that stores embeddings and finds the nearest ones fast. pgvector (Postgres), MongoDB Atlas Vector Search and Pinecone are common.
  5. RAGRetrieval-Augmented Generation: search your own data first, paste the best matches into the prompt, then let the model answer from them.
  6. Indexing (run once)Split your documents into chunks, embed each chunk, and store the chunk text with its vector.
  7. Querying (every question)Embed the question, fetch the closest chunks, and send them to the model with an instruction to answer only from that context.
  8. Answer only from contextTell the model to answer only from the retrieved text, and to say "I don't know" when the answer isn't there.
  9. Chunk sizeStart with 300 to 800 tokens per chunk and about 10% overlap. Split on headings and paragraphs, or functions for code.
  10. Top KHow many chunks you retrieve per question. Start with 3 to 5.
  11. MetadataStore the source file, section and date with each chunk.
  12. Hybrid searchCombine keyword search with vector search.
  13. Re-rankingA second model re-orders the top 20 results by relevance, then you keep the best few.
  14. Agentic RAGRetrieval becomes a tool, searchDocs(query). The agent decides when to search, and can search several times with different queries.