Skip to main content

Embedding models

Embedding turns text, images, or videos into numbers.

These models convert text, images, and videos into numbers. They then store them in a vector database.

Later, you can use these numbers to find similar items. You compare the numbers and pick the closest match. This is called vector search.

How RAG works with LLMs?

The AI agent pulls extra context from the vector database. It then passes that context to the LLM as part of the prompt to make the final output.

Note that the LLM doesn't call the vector database itself. The agent calls it. The agent gets the data and passes it to the LLM as context.

How does the database knows the limit of relevant chunks?

For a vector being queried, even the most remote chunk is related to the query vector but the relation is weak. By setting the top-k parameter, we can filter the most relevant chunks from the vector database.

embedding-models
why the word embedding

In AI, "embedding" means placing something complex into a simpler space. This space often has fewer dimensions. It still keeps the key traits and links.

In short, you place text, images, and videos into another space.

Vector and Graph databases

Vector databases is what's explained above. Just stores the chunks in a vector space. Whereas graph databases only stores the relationships between entities and a pure graph database doesn't need embedding models as well. If you know the exact entities and its relationships, then creating the graph database is straightforward.

GraphRAG

GraphRAG is an architecture where vector and graph databases are combined to provide a stronger solution.

  1. Queries always start from the vector index.
  2. The vector database returns the most relevant nodes.
  3. The graph data of the node is used to then fetch the related nodes.
what happens if it's a pure graph database?

If we've a pure graph database, the query will either have to send exact graph node names or scan through the entire graph. By adding a vector database on top will bring in semantic search to the same graph database.

graph-rag
Returning data from Graph databases

It's up to the implementation to decide how deep we can go in the graph or which of all the nodes at a specific level should be considered.

  • Use node degrees - if a node has many child nodes, consider only the first N child nodes which the maximum degree and ignore the rest.
  • Use hops - To say how many levels in the graph should be considered.