← 9 Session 10 - Approximate nearest neighbour search and search systems - Mon 12 Oct →
All decks
  1. 1 Why retrieval nowMon 31 Aug
  2. 2 The inverted indexWed 02 Sep
  3. 3 Index construction and ranking foundationsMon 07 Sep
  4. 4 BM25: finish probabilistic rankingWed 09 Sep
  5. 5 Evaluation and the changing goals of retrieval benchmarksMon 14 Sep
  6. 6 Coarse retrieval and rerankingWed 16 Sep
  7. 7 LLM embeddings and rerankingMon 28 Sep
  8. 9 Hard queries: reasoning and ambiguityWed 07 Oct
  9. 10 Approximate nearest neighbour search and search systemsMon 12 Oct
  10. 12 Attention as retrievalMon 19 Oct
  11. 14 Memory as an architectural axisMon 26 Oct
  12. 16 Memory learned at test timeMon 02 Nov
  13. 18 Language models with an index attachedMon 09 Nov
  14. 20 Retrieval-augmented generationMon 16 Nov
  15. 22 Agentic retrieval and deep researchMon 23 Nov
  16. 23 Agent memory: write, manage, readWed 25 Nov
  17. 24 Learning what to rememberMon 30 Nov
  18. 26 Evaluating agent memoryMon 07 Dec
  19. 28 Privacy, personalisation and unlearningMon 14 Dec
Contents
  1. 1Search systems
  2. 2Announcements
  3. 3Roadmap
  4. 4FAISS
  5. 5FAISS makes vector search practical
  6. 6Exact search is the reference
  7. 7Inverted file (IVF) search selects partitions
  8. 8HNSW: building
  9. 9HNSW: processing query
  10. 10Product quantisation (PQ): building
  11. 11PQ: processing query
  12. 12Which index fits the workload?
  13. 13Elasticsearch
  14. 14ElasticSearch: From nearest neighbours to a search service
  15. 15Chunking defines what we retrieve
  16. 16Index each chunk with its source
  17. 17Follow the query to its passages
  18. 18Deep Research
  19. 19From search results to deep research
  20. 20What should the investigation achieve?
  21. 21Benchmarks test different outputs
  22. 22How to build a deep-research system
  23. 23Anthropic's research system
  24. 24Anthropic’s research loop connects planning, workers, memory an…
  25. 25From a system description to open-source code
  26. 26Open Deep Research: the complete workflow
  27. 27From research brief to report
  28. 28How can we improve deep research?
  29. 29Coming up

The recording

1

Search systems

FAISS, Elasticsearch and deep research

Information Retrieval for AI

Monday 12 October 2026

KAIST AI - Seong Joon Oh

2

Announcements

Wednesday 14 October: guided paper-search workshop

14 October, 09:00-10:00 KST, on Zoom.

Open the workshop and follow the lecturer with the supplied starter. Access and the baseline run take place in class.

The workshop carries 2 project marks. Today’s vector DB and chunking material prepares the comparison.

Project rules

Next week: LIMIT discussion

Wednesday 21 October, 09:00-10:00 KST, on Zoom.

LIMIT: On the Theoretical Limitations of Embedding-Based Retrieval

Read the anchor and the relevant sections of one supporting paper you choose. Preparation is due Tuesday 20 October at 18:00 KST.

Discussion and preparation

3

Roadmap

Deep Research Plan, craft queries, assess results Elasticsearch Build a retrieval system FAISS Search vectors efficiently Prepare documents, retrieve, post-process Build a deep research system
4

FAISS

Facebook AI Similarity Search

Efficient nearest-neighbour search

Exact search, inverted files, graph search and product quantisation.

5

FAISS makes vector search practical

Coarse retrieval needs the nearest document vectors for a query. We already have embeddings and a similarity score. The problem is how to find the top matches efficiently as the corpus grows.

The cost: an exact scan scores every document vector for every query. Storing all full-precision vectors also consumes memory.

FAISS provides vector indexes with different trade-offs:

  • Exact search: efficient implementations on CPUs and GPUs.
  • IVF and HNSW: search selected lists or graph neighbours to reduce comparisons, with possible missed neighbours.
  • PQ: compress vectors into short codes to reduce storage, with approximate scores.

Choose an index and tune it for the required speed, memory and neighbour recall.

FAISS documentation

6

Exact search is the reference

Each input row is a passage or query embedding. embedding_dim is its number of coordinates.

def exact_search(
    passage_embeddings,  # shape: (num_passages, embedding_dim)
    query_embeddings,    # shape: (num_queries, embedding_dim)
    top_k,               # number of hits per query
):
    """Return (similarity_scores, passage_rows), each (num_queries, top_k).

    similarity_scores: inner products, highest first.
    passage_rows: row indices into passage_embeddings.
    """
    embedding_dim = passage_embeddings.shape[1]
    exact_index = faiss.IndexFlatIP(embedding_dim)
    exact_index.add(passage_embeddings)
    similarity_scores, passage_rows = exact_index.search(
        query_embeddings, top_k
    )
    return similarity_scores, passage_rows

exact_index scans every stored vector. Its returned neighbours define the reference for ANN recall, not relevance labels.

FAISS metrics

7

Inverted file (IVF) search selects partitions

Build

  1. Embed each document or passage.
  2. Compute centroids with k-means on a representative sample. Repeatedly assign vectors to the nearest centroid, then recompute centroids as cluster means.
  3. Assign every corpus vector to its nearest centroid. Store its vector and document ID in that centroid’s inverted list.

Query qCompare q with all 4 centroidsSelect the nearest 2 (nprobe = 2)C1List 1scanC2List 2scanC3List 3skipC4List 4skipRank vectors from the scanned listsReturn top-k neighbours

More probes scan more lists: higher search cost, fewer missed neighbours.

FAISS index documentation

8

HNSW: building

Hierarchical navigable small world (HNSW). Each node is a document vector; each edge is a stored link.

Same vectors, fewer nodes in higher layersLayer 2 (top)subset of layer 1AFLayer 1subset of layer 0ACFLayer 0 (bottom)every vectorABCDEFGHExample: random draws give C a maximum layer of 1C enters layer 0C also in layer 1Stop at layer 1draw u < pdraw u ≥ pEach draw: independent u, uniform between 0 and 1p is a fixed promotion probability. No fit or capacity test.Links shown schematically; distances guide neighbour selection.

  1. Route: C belongs to layers 1 and 0. Search layer 2 for a starting point.
  2. Connect: in layer 1, follow existing links to find nearby candidates. Select neighbours, add links both ways, and prune excess links.
  3. Repeat: use the candidates found to start the same process in layer 0.

M controls connectivity; efConstruction controls how broadly insertion searches for candidates.

HNSW paper, pp. 4-5, Algorithms 1-4

9

HNSW: processing query

1. Top: follow links greedilyQuery q2. Descendat thesame vector3. Bottom: explore with efSearchAFACFABCDEFGHReturn the best k neighbours foundLayer 2: topLayer 1Layer 0: bottom

  1. Top: start in layer 2. Follow stored links to vectors closer to the query.
  2. Descend: when no linked neighbour is closer, move down at the same vector. Repeat in layer 1, then descend to layer 0.
  3. Bottom: explore several paths through the links. Keep up to efSearch best vectors found.

Stop when no pending candidates remain, or the closest pending candidate is farther than the worst retained result. Return the best found.

Larger efSearch allows more exploration at greater cost. It limits retained results, not total visits; the answer remains approximate.

HNSW paper, pp. 4-5, Algorithms 2 and 5

10

Product quantisation (PQ): building

Split the same coordinates in every document. For each group, compute 256 centroids with k-means across documents. These form a shared codebook for that group.

1. Split 8 coordinates into 4 sub-vectorsSub-vector 1(x1, x2)Sub-vector 2(x3, x4)Sub-vector 3(x5, x6)Sub-vector 4(x7, x8)2. Choose the nearest centroid in each codebookCodebook 1256 entries17Codebook 2256 entries203Codebook 3256 entries6Codebook 4256 entries913. Store code IDs: one byte per sub-vector

Store the document as [17, 203, 6, 91]. Each index selects a centroid from its own codebook.

Toy example: bytes of float32 values become code bytes. Each index fits in 8 bits because . Shared codebooks and document IDs cost extra. Four groups is an example, not a requirement.

Product quantisation, §§2-3

11

PQ: processing query

1. Query arrives: split into the same four groupsQuery piece q1Score table T1q1 dot centroid 0…q1 dot centroid 255T1[17]Query piece q2Score table T2q2 dot centroid 0…q2 dot centroid 255T2[203]Query piece q3Score table T3q3 dot centroid 0…q3 dot centroid 255T3[6]Query piece q4Score table T4q4 dot centroid 0…q4 dot centroid 255T4[91]2. Compute 256 dot products per group, once for this query3. Document [17, 203, 6, 91] selects four table entriesAdd four entries → document score

Keep the query pieces uncompressed. The tables contain query-to-centroid dot products. Compute them when the query arrives; reuse them across documents.

Each document needs four lookups and a sum. Documents with the same centroid index reuse the same table entry. The result approximates the original dot product.

IndexPQ scans all codes; IndexIVFPQ scans codes in selected lists. Approximation can change neighbour order.

FAISS query score tables

12

Which index fits the workload?

MethodStoragePer-query computationSearch accuracy
ExactMediumHeavyExact neighbours
IVFMediumMediumCan miss neighbours in skipped lists
HNSWHeavyLightCan miss neighbours outside explored paths
PQLightMediumApproximate scores can change neighbour order

Search accuracy means agreement with exact vector search, not relevance to the query.

Typical guide for a large corpus. Hardware and recall settings can change these ratings; PQ saves memory but does not guarantee faster queries.

Connect each method to one context. Select a method, then a context. One point per correct match; submit once.

MethodUseful when
Your connections

Sign in with your course account to submit.

FAISS index choice

13

Elasticsearch

From a vector index to a search service

Chunk documents, index passages and retrieve evidence.

14

ElasticSearch: From nearest neighbours to a search service

We can now find nearby document vectors efficiently. What must happen around that search to serve a user?

“Find passages about battery recycling in papers published since 2024.”

  • Chunk and store documents: split documents into passages; keep each chunk’s text, embedding, publication date and source link together.
  • Retrieve candidates: match query words with BM25 and meaning with vector search.
  • Apply constraints: restrict results to eligible publication dates.
  • Operate the service: accept requests, update documents and distribute the index across machines.

Elasticsearch provides these capabilities through a search API. We will follow one passage record through keyword search, vector search and filters.

Its vector search uses Apache Lucene’s HNSW implementation. The graph-search principles we have studied still apply.

Elasticsearch’s integrated search design

15

Chunking defines what we retrieve

A chunk is the text unit we index, embed and return. Its boundaries determine which context stays together.

StrategySplit atBenefitLimitation
SentenceSentence boundariesKeeps sentences intactRelated sentences may separate
WordA word-count limitControls chunk lengthMay cut a sentence in half
RecursiveOrdered separators, then finer boundariesFollows document structureNeeds suitable separators
NoneNo additional splitRetains input or external chunksInput must fit the model limit

Boundary example: “Our battery recycling process recovered lithium. These results apply only to sorted cells.” Keep both sentences in Chunk A so the claim retains its qualification.

Size trades focused matches against context. Overlap can retain context across boundaries, but duplicates text and adds indexing work. Test both against retrieval examples and the embedding model’s input limit.

Adapted from Elastic’s chunking strategies.

16

Index each chunk with its source

Our example stores one Elasticsearch record per chunk. Compute its embedding with the same model used for queries.

Chunk A → one searchable passage recordpassage_id: p17:c1 (A)document_id: p17text:Our battery recycling process recoveredlithium. These results apply only to sorted cells.embedding: embed(the complete chunk text)year: 2025source: paper 17, page 4, sentences 1-2Inverted indexText terms → BM25Vector indexEmbedding → HNSWMetadataYear → eligibility filterA returned hit identifies the passage and its original source.

Text, vector and metadata describe the same passage ID. A hit can return the passage text and source location; the document ID groups passages from the same paper.

Elasticsearch’s integrated document and vector indexes

17

Follow the query to its passages

Constructed candidates and rankings, not measured results. A is the chunk from paper 17; B and D are passages from other papers.

“Find passages about battery recyclingin papers published since 2024.”Same date constraint in both searches: year ≥ 2024Eligible: A (2025), B (2024), D (2025) Excluded: C (2022)Query words → BM251. A 2. B 3. DA = paper 17, chunk 1Query embedding → HNSW1. B 2. D 3. ASame embedding model as the passagesElasticsearch merges the ranked listsOne ranked list of passageswith text and source locations

Filter placement

18

Deep Research

From search results to an evidence-based report

An agent chooses queries, checks evidence and writes the answer.

19

From search results to deep research

We can retrieve documents for a query. Who chooses the next query, decides whether the evidence is sufficient, and writes the answer?

Recall the laptop task: A PhD student needs a laptop for daily travel and large-dataset analysis: budget ₩2 million, weight at most 1.5 kg, RAM at least 32 GB. Compare three models sold in Korea, recommend one and cite the evidence.

Interactive search: search → results → a human checks evidence and directs the next search.

Deep research: search → results → an agent checks evidence and chooses further searches → report.

The user sets the objective. The agent uses search systems within a multi-step investigation. Human attention need not direct every search round.

A cheap 16 GB listing does not establish the price of the exact 32 GB configuration. The agent must find and check that missing evidence.

Constructed task from our earlier example. Anthropic’s research-system account, 2025

20

What should the investigation achieve?

Laptop task: Compare three models sold in Korea and recommend one within the stated budget, weight and RAM requirements.

  • Correctness and support: Verify each claim against the exact configuration and its cited source.
  • Breadth and depth: Cover the requested alternatives and criteria; explain the trade-offs and unresolved evidence.
  • Efficiency: Count elapsed time, tokens, tool calls and cost across the entire campaign.

A relevant result list is an intermediate output. Evaluate the final answer or report, then inspect the trace to explain failures.

Compare quality at a fixed budget, or cost at a stated quality target. State the source environment and judge.

DeepResearch Bench, §3 - DeepSearchQA

21

Benchmarks test different outputs

NameWhat’s measuredDataMetric
BrowseCompFind a hard-to-locate answerHuman-authored web questions with short reference answersAnswer accuracy
BrowseComp-PlusAnswer and evidence retrievalBrowseComp-derived questions; fixed web corpus and evidence labelsAnswer accuracy; evidence recall; retriever nDCG
DeepSearchQAReturn a complete, correct answer setMulti-step web questions with reference answer setsAnswer-set precision, recall and F1
DeepResearch BenchReport quality and citation supportExpert-written research tasks and reference reportsRACE report score; FACT citation accuracy and effective citation count

Record time, tokens and tool cost beside quality. The tasks and judges differ; their scores are not interchangeable.

22

How to build a deep-research system

Request → research brief → model chooses an action → harness executes a tool → model reads the observation → further research → report.

Model: Proposes queries, source inspections and conclusions from the available evidence.

Harness: Runs tools, routes work, retains state and enforces limits.

Workflow: Connects clarification, research and report generation. It specifies where evidence and output checks occur.

Compare Anthropic’s published architecture with an open research model and source code for a report-producing harness.

Anthropic - Open Deep Research

23

Anthropic’s research system

Anthropic Research architecture, June 2025. Lead agent, search workers, memory and citation stage. The figure uses Anthropic’s company-search example; our laptop delegation follows below.
Anthropic Research architecture, June 2025. Lead agent, search workers, memory and citation stage. The figure uses Anthropic’s company-search example; our laptop delegation follows below.

The lead researcher plans the investigation and delegates branches to workers with separate contexts. It combines their findings; a citation stage attaches sources.

For laptops, give each worker one candidate and the same requirements. The lead must reconcile configuration differences before comparison.

Parallel work adds breadth and token cost. This is the architecture described in June 2025.

Engineering account

24
Anthropic’s multi-agent research process: planning and memory, iterative subagent research, synthesis, then citation insertion.
Anthropic’s multi-agent research process: planning and memory, iterative subagent research, synthesis, then citation insertion.
25

From a system description to open-source code

We now move from Anthropic’s published architecture to an implementation we can inspect.

Which implementation? LangChain’s Open Deep Research, a Python research workflow built with LangGraph. It connects language models and search tools to turn a user request into a research report. We inspect revision 1b7d2e80 of the archived repository.

Goal of the dissection: Trace how the laptop request becomes a report, and locate the code that controls quality and cost.

  1. Workflow and state: How does the request become a brief, and what information reaches each stage?
  2. Delegation and tools: How are workers launched, what do they receive, and how do their results return?
  3. Evidence and stopping: What survives compression, when does research stop, and what reaches the writer?

Open Deep Research repository - Source revision

26

Open Deep Research: the complete workflow

START: user requestResearch brief₩2m / ≤1.5 kg / ≥32 GBSupervisor assigns researchParallel workersWorker A: laptop ASearch ↔ readWorker B: laptop BSearch ↔ readWorker C: laptop CSearch ↔ readWorkers compress findingsSummaries → supervisorRaw notesStoredNot passedto writerSupervisor finishedor limit reached?No: more researchYesFinal writerBrief + collected summariesEND: report returned to user

The supervisor reappears at the decision point. Stop triggers: completion signal, no tool call, or iteration limit.

Implementation

27

From research brief to report

  1. Brief and supervisor: turn the request into a shared brief. The supervisor assigns topics and reviews workers’ summaries.
  2. Parallel workers: each agent searches and reads with its own tools and conversation. The harness limits concurrent tasks; workers return summaries and raw notes.
  3. Stop and write: the supervisor can request more research. A completion signal, no tool call or an iteration limit ends the loop. The writer receives the brief and collected summaries; raw notes stay separate.

Preserve the evidence through each hand-off. For the laptop task, retain the ₩2 million budget, 1.5 kg weight limit and 32 GB requirement. A summary that drops “16 GB” from a low-price listing may support the wrong recommendation. Reaching a stopping condition does not guarantee complete evidence.

Brief and supervisor - Workers and returned results - Stopping rules - Compression and writer

28

How can we improve deep research?

The agent can make a poor decision, the workflow can lose evidence, or search can miss it. Each calls for a different improvement.

DirectionWhat we changePrior work and its evidence
Model trainingClarification, queries and tool use. For the laptop task, ask about an unstated RAM requirement.Search-R1 improved search-assisted QA, not established long-report quality. IntentRL improved clarification and research performance with simulated users.
Harness designDelegation, tool instructions and evidence hand-offs. Keep the configuration beside each price through compression.Anthropic reports shorter completion times after tool-description improvements and parallel agent/tool execution in its research system.
Retrieval systemSources, matching, context and reranking. Retrieve the Korean listing for the exact laptop configuration.Contextual Retrieval reduced retrieval failures with contextualised chunks, BM25 plus embeddings, and reranking. It measured RAG retrieval recall, not research-report quality.

Test whether a change improves supported report quality at the same cost, or reduces cost at the same quality. Test components separately before combinations.

29

Coming up

Wednesday 14 October - paper-search workshop

09:00-10:00 KST, on Zoom.

A guided, hands-on session with a paper-search system. Explore how retrieval choices affect its results.

Workshop and instructions

Next Wednesday 21 October - LIMIT discussion

09:00-10:00 KST, on Zoom.

LIMIT: On the Theoretical Limitations of Embedding-Based Retrieval

Read the anchor paper and the relevant sections of one supporting paper. Preparation is due Tuesday 20 October at 18:00 KST.

Discussion and preparation