AI ARCHITECTURE /// VECTOR DATABASES /// EMBEDDINGS /// RAG PIPELINE /// AI ARCHITECTURE /// VECTOR DATABASES /// EMBEDDINGS ///

Connecting A Vector DB

Give your LLMs a long-term memory. Master embeddings, semantic search, and the RAG architecture.

database.ts
1 / 7
🧠

Tutor:LLMs are stateless. To give them memory of your specific documents, we use Vector Databases. But first, we need Embeddings.


Vector Matrix

UNLOCK NODES BY MASTERING SEARCH.

Concept: Embeddings

An embedding takes a string of text and maps it into a dense vector of floating-point numbers.

System Check

What API generates embeddings in the standard OpenAI ecosystem?


Vector Databases: Giving AI a Memory

Author

Pascual Vila

AI Architect // Code Syllabus

"LLMs are brilliant but amnesiac. Without a vector database, your AI is trapped entirely within its training cutoff date."

Understanding Embeddings

Before we can search unstructured data (like text, images, or audio), we must convert it into a format machines can understand: mathematical arrays called embeddings. An embedding represents the "semantic meaning" of data. Words with similar meanings exist closer together in this multi-dimensional mathematical space.

Why Not PostgreSQL?

Standard relational databases query using exact keyword matches (e.g., SELECT * WHERE text LIKE '%dog%'). If the user searches for "canine", standard SQL finds nothing. Vector databases calculate distance metrics (like Cosine Similarity) between the user's query vector and stored vectors, allowing it to realize that "canine" and "dog" are mathematically close.

AI Engineering FAQ

What is the difference between a relational database and a vector database?

Relational Databases (like PostgreSQL, MySQL) store data in rows and columns and rely on exact keyword or pattern matches. They are excellent for structured, tabular data.

Vector Databases (like Pinecone, Weaviate, Qdrant) store high-dimensional arrays (embeddings). They use algorithms like Approximate Nearest Neighbor (ANN) to find data based on semantic similarity, making them essential for AI context retrieval.

What is Cosine Similarity?

Cosine similarity is a mathematical metric used to determine how similar two vectors are, irrespective of their size. It measures the cosine of the angle between two vectors projected in a multi-dimensional space.

  • 1.0: Vectors point in exactly the same direction (perfect semantic match).
  • 0.0: Vectors are orthogonal (unrelated).
  • -1.0: Vectors point in opposite directions (opposite meaning).
How do Vector Databases work with LLMs in RAG?

RAG (Retrieval-Augmented Generation) connects LLMs to custom data. The workflow is:

  1. The user sends a prompt.
  2. The application converts the prompt into an embedding vector.
  3. The application queries the vector database using that vector.
  4. The database returns the top K most semantically similar text chunks.
  5. The application injects those text chunks into the system prompt alongside the user's original query, allowing the LLM to generate an answer based on private data.

AI Architecture Glossary

Embedding
A representation of text, images, or audio as an array of floating point numbers (a vector).
concept.js
Vector Database
A specialized database designed to efficiently store and query high-dimensional vectors.
concept.js
Cosine Similarity
A metric used to measure how similar two vectors are by looking at the angle between them.
concept.js
RAG
Retrieval-Augmented Generation. Supplying an LLM with relevant facts pulled from a Vector DB.
concept.js
Dimensions
The length of the vector array. Must match between your embedding model and DB index.
concept.js
Top-K
The parameter defining how many similar results the database should return.
concept.js