Embeddings e database vettoriali
Comprenda come gli embeddings trasformano il significato in vettori e come i database vettoriali abilitano la fase di retrieval al cuore del RAG.
Embeddings e database vettoriali è una lezione LangChain / RAG / Vector DBs gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento LangChain / RAG / Vector DBs, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso LangChain / RAG / Vector DBs include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
From Words to Vectors
Computers cannot compare meaning directly. An embedding is a vector of numbers representing a text’s meaning, so similar texts land close together.
What an Embedding Looks Like
An embedding model maps text to a fixed-length vector with hundreds or thousands of dimensions. The numbers are not readable — what counts is their geometric relationships.
text = 'a cup of coffee'
embedding = [0.12, -0.04, 0.88, 0.31] # simplified
print('dimensions:', len(embedding))Semantic Similarity
Because meaning maps to position, "dog" sits near "puppy" but far from "database". That is what powers semantic search — matching by meaning, not exact keywords.
Measuring Closeness
The go-to closeness metric is cosine similarity — the cosine of the angle between two vectors. 1 means nearly identical, 0 means unrelated.
def cosine(a, b):
dot = sum(x*y for x, y in zip(a, b))
na = sum(x*x for x in a) ** 0.5
nb = sum(y*y for y in b) ** 0.5
return dot / (na * nb)
print(round(cosine([1, 0, 1], [1, 0, 1]), 2))
print(round(cosine([1, 0, 0], [0, 1, 0]), 2))Why a Vector Database?
RAG must find the most relevant chunks among millions of vectors, fast. A vector database stores embeddings and finds nearest neighbors — something SQL is not built for.
Approximate Nearest Neighbor
Comparing a query to every vector is too slow at scale. Vector DBs use ANN indexes like HNSW that trade a sliver of accuracy for huge speed gains.
Indexing Documents
To build a knowledge base, index your docs: split into chunks, embed each one, and store the vector with its text and metadata. This is RAG’s offline ingestion step.
chunks = ['intro paragraph', 'pricing details', 'support hours']
for c in chunks:
vec = embed(c) # call embedding model
db.upsert(vec, text=c)Querying
At query time, embed the user’s question with the same model, then ask the vector DB for the top-k nearest chunks — that becomes the LLM’s context.
q_vec = embed('when is support open?')
results = db.search(q_vec, top_k=3)
for r in results:
print(r.text, r.score)Metadata Filtering
Vector DBs also support metadata filtering: combine similarity search with filters like language, date range, or owner to sharpen relevance.
db.search(q_vec, top_k=3, filter={'lang': 'en', 'year': 2026})Choosing a Vector Store
Your vector store options span libraries (FAISS), dedicated DBs (Pinecone, Weaviate, Qdrant, Milvus), and extensions like pgvector. Pick by scale, hosting, and data needs.
Embeddings in the RAG Pipeline
Embeddings and the vector DB are the retrieval half of RAG: index once, then for every question embed, search, and hand the top chunks to the LLM as grounding.
Quick Check
Test your understanding of embeddings and vector search.
Recap
You learned RAG’s retrieval foundation: embeddings turn meaning into vectors, cosine measures closeness, and vector DBs use ANN for fast nearest-neighbor search.
Domande Frequenti
La lezione «Embeddings e database vettoriali» è gratuita?
Sì — il testo completo di «Embeddings e database vettoriali» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso LangChain / RAG / Vector DBs, passa a CoddyKit PRO. Il corso LangChain / RAG / Vector DBs include 4 lezioni in totale.
Cosa imparerò in «Embeddings e database vettoriali»?
Comprenda come gli embeddings trasformano il significato in vettori e come i database vettoriali abilitano la fase di retrieval al cuore del RAG. Eserciti LangChain / RAG / Vector DBs con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare LangChain / RAG / Vector DBs?
Non è richiesta alcuna esperienza precedente. LangChain / RAG / Vector DBs su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Embeddings e database vettoriali»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione LangChain / RAG / Vector DBs?
Sì. Ogni lezione LangChain / RAG / Vector DBs include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Che cosa sono i large language model?
- La necessità della Retrieval Augmented Generation
- Componenti fondamentali di un sistema RAG
- Embeddings e database vettoriali