Retrieval pipeline
document → parse → chunk → metadata → embedding/index
query → transform/filter → retrieve top-k → optional rerank → context- Indexing and query-time behaviour both affect evidence quality.
Learn how text can be represented numerically so similar ideas can be found even when they use different words. Then compare keyword, vector and hybrid retrieval and measure whether search actually finds the right evidence.
Engineering focus: Embeddings, semantic search and retrieval
Learn how text can be represented numerically so similar ideas can be found even when they use different words. Then compare keyword, vector and hybrid retrieval and measure whether search actually finds the right evidence.
The rest of this module introduces the formal terminology and production controls behind that idea. You are not expected to memorize the vocabulary before using it.
Carry the same support assistant forward: approved KB, source citations, explicit insufficient-evidence fallback and one bounded read-only asset lookup. Reuse prior artifacts so each module adds evidence to one production AI system.
Embedding models map inputs to numeric vectors so semantically related items can be compared. They do not provide truth, permissions or freshness by themselves.
A chunk should be large enough to preserve the fact needed to answer, but small enough to avoid irrelevant context. Structure-aware splitting by headings, paragraphs or records often beats fixed-size chopping.
Source ID, title, timestamp, product, access label and version enable filtering, citation and freshness decisions. A vector database without useful metadata is difficult to govern.
Exact IDs, error codes, names and rare tokens may be better served by lexical search. Hybrid retrieval combines semantic and lexical evidence, then can rerank the candidate set.
Measure whether the correct evidence appears in top-k results. If retrieval recall is poor, changing the generation prompt cannot create missing evidence reliably.
document → parse → chunk → metadata → embedding/index
query → transform/filter → retrieve top-k → optional rerank → contextRetrieval: Did we fetch the evidence needed?
Generation: Did the model use the fetched evidence correctly?Goal: Implement a simple lexical baseline first so retrieval quality can be measured without a model dependency.
cat > /tmp/atlas-kb.json <<'EOF'
[
{"id":"kb-17","text":"Password reset requires service desk approval and identity verification."},
{"id":"kb-22","text":"Database maintenance occurs Sundays at 02:00 UTC."},
{"id":"kb-31","text":"Asset srv-104 belongs to the payments service."}
]
EOFpython3 - <<'PY2'
import json,re
kb=json.load(open('/tmp/atlas-kb.json'))
def toks(s): return set(re.findall(r'[a-z0-9-]+',s.lower()))
def search(q):
q=toks(q); return sorted(kb,key=lambda d:len(q&toks(d['text'])),reverse=True)
for q,expected in [('How do I reset a password?','kb-17'),('When is database maintenance?','kb-22')]:
top=search(q)[0]['id']; print(q,'->',top); assert top==expected
print('PASS: baseline retrieval')
PY2Create at least five query→expected-source cases, including one exact identifier and one paraphrase. Later compare lexical and embedding retrieval on the same cases.
A strong RAG system starts with measurable information retrieval, not with a vector database brand.
Generate normalized embeddings and compare semantic similarity for the same small KB.
EMBED_MODEL=${EMBED_MODEL:-embeddinggemma}; ollama list | headEMBED_MODEL=${EMBED_MODEL:-embeddinggemma}; curl -s http://127.0.0.1:11434/api/embed -H 'Content-Type: application/json' -d "{\"model\":\"$EMBED_MODEL\",\"input\":[\"Password reset requires approval\",\"How can I change my password?\"]}" > /tmp/embed.jsonpython3 - <<'PY2'
import json,math
x=json.load(open('/tmp/embed.json'))['embeddings']
a,b=x[0],x[1]
dot=sum(i*j for i,j in zip(a,b)); print('cosine/dot for normalized vectors:',round(dot,4),'dims',len(a))
PY2Concept and scenario checks. Reveal the answer only after you commit to a decision.
A numeric representation useful for similarity; it does not provide truth or authorization.
It enables filtering, access control inputs, freshness/version reasoning, citation and source attribution.
For exact identifiers, rare terms, error codes and other token-sensitive queries.
Retrieval/indexing/query design, because generation cannot reliably use evidence it never received.
Progress is saved in this browser immediately. When you sign in to My Learning, it can also sync across devices.
Attempt the core lab and knowledge checks before marking the module complete.