TodayTools

RAG and vector databases flashcards

Make AI answer from your own documents, with sources you can check.

Donate
Beginner friendly, starts from zero
Section
How to study
0
RAG and vector databasesStart from zero · 1 of 11

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.

Look it up, then answer.
Show again
11 left
Got it

Tap to turn over. Swipe right if you know it, left to see it again.

All topics

What you will learn

  1. Start from zero

    • What RAG is and why it exists4 cards
    • The key words5 cards
    • Trust and limits2 cards
  2. Core basics

    • The RAG pipeline3 cards
    • Embeddings and similarity4 cards
    • Chunking basics2 cards
    • Vector stores4 cards
    • Prompting with context5 cards
  3. 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
  4. 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 test

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. 1. Start from zero (11 cards): What RAG is, why AI needs it, and the words you need before Core basics.
  2. 2. Core basics (18 cards): The pipeline, embeddings, pgvector and prompting with sources.
  3. 3. Next steps (18 cards): Hybrid search, reranking, access filters, indexes, evals and freshness.
  4. 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 database
  • embedding vector(384) Column for 384-number vectors
  • embedding halfvec(1536) Half-precision vectors, half the size
  • <=> Cosine distance, smaller is closer
  • <-> Euclidean (L2) distance
  • <#> Negative inner product
  • 1 - (a <=> b) Cosine similarity score

Indexes and tuning

  • USING hnsw (embedding vector_cosine_ops) Graph index for cosine queries
  • WITH (m = 16, ef_construction = 64) HNSW build settings (defaults)
  • SET hnsw.ef_search = 100; Wider search, better recall
  • USING ivfflat ... WITH (lists = 100) List-based index, build after loading data
  • SET ivfflat.probes = 10; Lists checked per query
  • SET hnsw.iterative_scan = relaxed_order; Keep scanning when filters remove rows

Pipeline defaults to start with

  • chunk 300 to 800 tokens Starting chunk size
  • overlap 10 to 20 percent Keep edge sentences in two chunks
  • top 50 then rerank to 5 Wide recall, sharp context
  • RRF k = 60 Fuse keyword and vector lists
  • min score floor Say "I do not know" on weak matches

Metrics

  • recall@k Right chunk in top k
  • MRR How high the first right chunk ranks
  • faithfulness Claims backed by sources
  • citation accuracy Cited chunk really says it
  • refusal rate Share of honest "I do not know"

Chunk metadata

  • source, page For citations
  • title_path Heading trail like "Returns > Laptops"
  • tenant_id, allowed_groups Access filters
  • version, effective_date Freshness filters
  • content_hash Skip re-embedding unchanged text
  • embed_model Model that made the vector
Donate