In [ ]:
Copied!
# --- Colab setup (skipped when running locally) ---
import os, sys
if 'google.colab' in sys.modules and not os.path.exists('data/sample_corpus.json'):
!git clone -q https://github.com/mdhabibi/llm-search-handbook.git
%cd llm-search-handbook
!pip -q install -r requirements.txt
# --- Colab setup (skipped when running locally) ---
import os, sys
if 'google.colab' in sys.modules and not os.path.exists('data/sample_corpus.json'):
!git clone -q https://github.com/mdhabibi/llm-search-handbook.git
%cd llm-search-handbook
!pip -q install -r requirements.txt
Chapter 0 — 5-Minute Pipeline Tour¶
See the destination before learning each part. We stand up a search system in a few cells and ask it questions. Every piece here gets built from scratch in later chapters.
Setup¶
pip install sentence-transformers rank-bm25
In [ ]:
Copied!
# Bootstrap: locate repo root and import shared helpers
import sys, os, json
d = os.getcwd()
while d != os.path.dirname(d) and not os.path.exists(os.path.join(d, 'data', 'sample_corpus.json')):
d = os.path.dirname(d)
ROOT = d; sys.path.insert(0, os.path.join(ROOT, 'src'))
import numpy as np
from corpus import load_corpus
# Bootstrap: locate repo root and import shared helpers
import sys, os, json
d = os.getcwd()
while d != os.path.dirname(d) and not os.path.exists(os.path.join(d, 'data', 'sample_corpus.json')):
d = os.path.dirname(d)
ROOT = d; sys.path.insert(0, os.path.join(ROOT, 'src'))
import numpy as np
from corpus import load_corpus
Build a search system in 3 lines¶
SearchStack bundles the whole course (chunk → hybrid retrieve → optional re-rank/generate). We'll use it search-only for the tour.
In [ ]:
Copied!
from search_stack import SearchStack
from sentence_transformers import SentenceTransformer
embedder = SentenceTransformer('all-MiniLM-L6-v2')
stack = SearchStack(embedder.encode, use_hybrid=True).ingest(load_corpus())
print('Ready. Ask it anything about the corpus.')
from search_stack import SearchStack
from sentence_transformers import SentenceTransformer
embedder = SentenceTransformer('all-MiniLM-L6-v2')
stack = SearchStack(embedder.encode, use_hybrid=True).ingest(load_corpus())
print('Ready. Ask it anything about the corpus.')
Ask by meaning, not keywords¶
Notice the answers match meaning — no shared-word requirement (the whole point of the course).
In [ ]:
Copied!
for q in ['why is grass green?',
'a large ocean animal',
'strong pain in the side of the head']:
top = stack.search(q, k=1)[0]
print(f'Q: {q}')
print(f' -> {top["title"]}\n')
for q in ['why is grass green?',
'a large ocean animal',
'strong pain in the side of the head']:
top = stack.search(q, k=1)[0]
print(f'Q: {q}')
print(f' -> {top["title"]}\n')
What you just used¶
- Chunking + ingestion → Chapter 11
- Keyword (BM25) + dense retrieval, fused → Chapters 2, 5, 8
- Embeddings that capture meaning → Chapters 3, 4
- (Optional) re-ranking and RAG answers → Chapters 7, 10
Now start at Chapter 1 and build each piece yourself. Welcome aboard!