RAG and vector databases flashcards
Make AI answer from your own documents, with sources you can check.
What is RAG, in one plain sentence?
-augmented generation: before the AI answers, it looks up the most useful pieces of your documents and answers from them, like a student allowed to use the textbook.
Tap to turn over. Swipe right if you know it, left to see it again.
What you will learn
Start from zero
- What RAG is and why it exists4 cards
- The key words5 cards
- Trust and limits2 cards
Core basics
- The RAG pipeline3 cards
- Embeddings and similarity4 cards
- Chunking basics2 cards
- Vector stores4 cards
- Prompting with context5 cards
Next steps
- Hybrid search3 cards
- Reranking2 cards
- Metadata and access2 cards
- Vector indexes3 cards
- Better chunking2 cards
- Query transformation2 cards
- Measuring retrieval2 cards
- Keeping the index fresh2 cards
Go deeper
- ANN internals4 cards
- Compression and cost3 cards
- Advanced retrieval3 cards
- Agentic RAG2 cards
- Evaluating answers2 cards
- Security2 cards
- Production2 cards
Final test and certificate
10 questions drawn fresh from the whole topic, about 15 minutes. Sign in, score 80% or more and get a free certificate with your name and a public check link anyone can open, such as an employer or a teacher. Not signed in? Try a practice test from the cards.
Take the final testAbout these cards
- Reviewed 26 October 2026
- Coverspgvector 0.8PostgreSQL 18Python 3.13sentence-transformers 5
Checked against
- pgvector: open-source vector similarity search for Postgres
- PostgreSQL documentation: full text search
- Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
- Malkov and Yashunin, HNSW graphs for approximate nearest neighbour search
- Claude docs: embeddings
- OWASP Top 10 for LLM Applications
RAG and vector databases at a glance
RAG lets an AI look up the right pages in your own documents first, then answer from them and show where the answer came from.
An open-book exam: instead of answering from memory, the student finds the right page in the textbook, reads it, then writes the answer and notes the page number.
Words you will meet
- Chunk
- A small piece cut from a long document, a few paragraphs long
- Embedding
- A list of numbers that stands for the meaning of a piece of text
- Vector
- Another name for that list of numbers
- Vector database
- A store that quickly finds the vectors closest to a question
- Similarity search
- Finding pieces with the closest meaning, even when the words differ
- Retrieval
- The look-up step that fetches the best chunks for a question
- Grounding
- Making the AI answer only from the fetched chunks
- Citation
- A pointer to the page or file the answer came from
The steps
- 1. Start from zero (11 cards): What RAG is, why AI needs it, and the words you need before Core basics.
- 2. Core basics (18 cards): The pipeline, embeddings, pgvector and prompting with sources.
- 3. Next steps (18 cards): Hybrid search, reranking, access filters, indexes, evals and freshness.
- 4. Go deeper (18 cards): ANN internals, compression, advanced retrieval, judging answers, security and production.
All 11 cards in Start from zero
- What is RAG, in one plain sentence?
- Retrieval-augmented generation: before the AI answers, it looks up the most useful pieces of your documents and answers from them, like a student allowed to use the textbook.
- An AI chat app was trained last year. Why can it not answer "what is our leave policy"?
- It only knows what was in its training text, which never included your private files or anything after its cut-off date. RAG hands it the right pages at question time.
- Why not just paste the whole policy book into the chat every time?
- Long books may not fit, every word you send costs money and time, and the AI pays less attention to facts buried in the middle. Sending only the few right pages is faster, cheaper and more accurate.
- Where have you already met RAG without knowing it?
- A bank help chat that quotes its FAQ, a "chat with this PDF" button, an office search box that finds "money back" when the file says "refund", and AI answers that list their sources underneath.
- What is a chunk?
- A small piece cut from a long document, usually a few paragraphs. A 200-page manual might become 800 chunks, so the search can return just the right bit.
- What is an embedding (also called a vector)?
- A long list of numbers, often hundreds of them, that an AI model makes from a piece of text. Texts with similar meaning get similar numbers, so "refund" and "money back" land close together.
- What is similarity search?
- Finding the chunks whose numbers sit closest to the numbers of the question. It matches meaning, so "my parcel never came" can find a chunk titled "Lost deliveries".
- What is a vector database?
- A store built to keep millions of embeddings and find the closest ones to a question in milliseconds. It can be a separate product or an add-on to a normal database such as PostgreSQL.
- What are retrieval and grounding?
- Retrieval is the look-up step that fetches the best chunks. Grounding means telling the AI to answer only from those chunks and to say "I do not know" when they do not contain the answer.
- Why should a good RAG answer show citations?
- A citation points to the file and page the answer came from, so you can click and check it. If an answer has no source, treat it as a guess.
- What can still go wrong with RAG?
- If the look-up fetches the wrong chunk, the answer is wrong but sounds sure. Old documents give old answers, and a chunk can be cut in the middle of a rule. Most RAG fixes are about better look-up.
RAG and vector databases cheatsheet
pgvector basics
CREATE EXTENSION vector;Enable pgvector in a databaseembedding vector(384)Column for 384-number vectorsembedding halfvec(1536)Half-precision vectors, half the size<=>Cosine distance, smaller is closer<->Euclidean (L2) distance<#>Negative inner product1 - (a <=> b)Cosine similarity score
Indexes and tuning
USING hnsw (embedding vector_cosine_ops)Graph index for cosine queriesWITH (m = 16, ef_construction = 64)HNSW build settings (defaults)SET hnsw.ef_search = 100;Wider search, better recallUSING ivfflat ... WITH (lists = 100)List-based index, build after loading dataSET ivfflat.probes = 10;Lists checked per querySET hnsw.iterative_scan = relaxed_order;Keep scanning when filters remove rows
Pipeline defaults to start with
chunk 300 to 800 tokensStarting chunk sizeoverlap 10 to 20 percentKeep edge sentences in two chunkstop 50 then rerank to 5Wide recall, sharp contextRRF k = 60Fuse keyword and vector listsmin score floorSay "I do not know" on weak matches
Metrics
recall@kRight chunk in top kMRRHow high the first right chunk ranksfaithfulnessClaims backed by sourcescitation accuracyCited chunk really says itrefusal rateShare of honest "I do not know"
Chunk metadata
source, pageFor citationstitle_pathHeading trail like "Returns > Laptops"tenant_id, allowed_groupsAccess filtersversion, effective_dateFreshness filterscontent_hashSkip re-embedding unchanged textembed_modelModel that made the vector