Tech, ExplainedData platforms and AI
Part

Vector database

Finding passages by meaning, not words.

INSIDE: RETRIEVAL-AUGMENTED GENERATION (RAG)HOW IT WORKS · A FARMERS' HELPLINE IN BHUBANESWAR FINDS THE RIGHT CIRCULAR40,000 circularpassages arestored as 768numbers eachA farmer asksin Odia aboutmoney fordrip irrigationThe questionis turned into768 numbersThe indexchecks about2,000 vectors,not all 40,000The 5 closestpassagescome back in20 millisecondsThe best matchis themicro-irrigationsubsidy circularINSIDE: RETRIEVAL-AUGMENTED GENERATION (RAG)HOW IT WORKS · A FARMERS' HELPLINE IN BHUBANESWARFINDS THE RIGHT CIRCULAR40,000 circularpassages are storedas 768 numbers eachA farmer asks inOdia about moneyfor drip irrigationThe question is turnedinto 768 numbersThe index checksabout 2,000 vectors,not all 40,000The 5 closestpassages come backin 20 millisecondsThe best match isthe micro-irrigationsubsidy circularINSIDE: RETRIEVAL-AUGMENTED GENERATION (RAG) ·A FARMERS' HELPLINE IN BHUBANESWAR FINDS THERIGHT CIRCULAR40,000 circular passages are stored as768 numbers each↓A farmer asks in Odia about money fordrip irrigation↓The question is turned into 768 numbers↓The index checks about 2,000 vectors, notall 40,000↓The 5 closest passages comeback in 20 milliseconds↓The best match is the micro-irrigationsubsidy circular
The vector database turns a farmer's question into 768 numbers, checks about 2,000 of 40,000 stored passages and returns the five closest, led by the circular on the micro-irrigation subsidy.
opens a page inside this one a page in the same scene a page in another scene a concept page a label only, with no page

A vector database is a database that stores text, images or other data as vectors, which are lists of numbers that capture meaning, and finds the stored items whose meaning is closest to a question. It lets a model find a passage by what it means, even when the passage uses different words from the question. It is the usual memory behind retrieval-augmented generation (RAG).

The numbers come from an embedding model. This is a model trained to turn a piece of text into a list of numbers of fixed length, for example 768 numbers. Texts with similar meanings get similar lists. 'Subsidy for drip irrigation' and 'financial help for micro-irrigation' end up close together, even though they share almost no words. The page on vector embeddings explains how a model learns to do this.

Finding the closest vectors is the hard part. Comparing a question with every one of a crore stored vectors would be too slow. So a vector database builds an index, a structure that lets it check only a small share of the vectors. A common kind of index links each vector to its nearest neighbours, like a map of roads between nearby towns. The search starts at one point and keeps moving to whichever neighbour is closer to the question, until no neighbour is closer. This is called approximate nearest-neighbour search. It may occasionally miss the very closest item, but it answers in milliseconds.

Consider the farmers' helpline of a state agriculture department in Bhubaneswar. It stores 40,000 passages from scheme circulars, each as 768 numbers. A farmer asks, in Odia, about money for drip irrigation. The question is turned into 768 numbers too. The database checks about 2,000 of the 40,000 stored vectors, not all of them, and returns the 5 closest passages in 20 milliseconds. The best match is a passage from a circular on the 'micro-irrigation subsidy', which never uses the word 'drip'. A search by keywords would have missed it.

How is this different from keyword search, as in enterprise search? Keyword search finds documents that contain the same words as the question. A vector database finds documents with the same meaning. Many systems now use both and combine the results. Vectors can also be stored inside a general database, such as a multi-model database, instead of a separate one. Matching a CV with a job by meaning, in semantic job matching, uses the same idea.

Who builds it

Tech, Explained is a part of ingrid.fyi. Every page explains one piece of technology in plain words.