Subtitle: Understanding embeddings, similarity search, metadata filtering, and the architecture behind modern AI applications.
When building an AI application, one of the first challenges is finding the right information from a large collection of documents.
Imagine an engineering organisation with thousands of technical manuals, design reports, research papers, and troubleshooting records. A user asks:
“How can we reduce vibration in a rotating machine?”
A conventional keyword search might look for documents containing the word “vibration.” But useful information could also appear in documents discussing rotor imbalance, resonance, bearing faults, or dynamic stability.
The information is related even when the exact words are different.
This is where vector embeddings and vector search become useful.
They provide a way to represent data numerically and retrieve information based on patterns of similarity. These technologies are widely used in semantic search, recommendation systems, image retrieval, and Retrieval-Augmented Generation (RAG).
However, understanding how they work—and where they fall short—is essential before choosing a database or designing an AI application.
1. What is a vector embedding?
An embedding is a numerical representation of information, such as text, an image, or another type of data.
An embedding model converts the input into a list of numbers called a vector.
For example, a text embedding might conceptually look like this:
[0.12, -0.38, 0.74, 0.05, ...]Real embeddings typically contain many dimensions. The numbers are not individual words or manually assigned categories. They are learned numerical representations intended to capture useful patterns in the input.
The important property is that an embedding model can place semantically related inputs near one another in its vector space.
For example, depending on the model and its training:
“Reduce machine vibration”
“Diagnose excessive rotor oscillation”
“Investigate rotating equipment instability”
may produce vectors that are relatively close to each other.
This makes it possible to retrieve relevant content even when the query and the document use different terminology.
However, embeddings do not understand information in exactly the same way a human expert does. Their usefulness depends on the embedding model, the content, the task, and how similarity is measured.
2. How does vector similarity work?
Once text has been converted into vectors, the system needs a way to compare them.
A common approach is cosine similarity, which measures the cosine of the angle between two vectors.
For vectors (A) and (B):
[
\operatorname{cosine}(A,B)=
\frac{A\cdot B}{|A||B|}
]
For non-zero vectors, the score ranges from -1 to 1 mathematically. In many embedding systems, useful similarity scores are predominantly positive, but the interpretation depends on the model and its training.
A higher cosine similarity often indicates that two vectors are more closely aligned. It does not automatically mean that the corresponding statements are factually equivalent.
Other approaches include Euclidean distance and dot-product similarity. The appropriate metric depends on the embedding model and the indexing configuration. Some models are designed to work with normalised embeddings, making different similarity calculations equivalent in ranking under those conditions.
A practical lesson is to follow the embedding model's recommendations instead of selecting a metric arbitrarily.
3. What does a vector database actually do?
A vector database stores embeddings and provides methods to search for similar vectors.
In a typical document-search application, a record may contain:
A vector embedding.
The original text or a reference to it.
A document identifier.
A section or page number.
A document version.
Metadata such as project, category, or publication date.
Access-control information where required.
When a user submits a query, the application generates a query embedding and searches for nearby vectors.
The database returns candidate records, often ordered by a similarity or distance measure.
The application can then retrieve the associated text and use it for display, further ranking, or AI-generated responses.
A vector database is therefore more than a place to store lists of numbers. It provides search capabilities and may also support metadata filtering, indexing, updates, deletion, and scaling.
The precise capabilities vary by database product.
4. Understanding approximate nearest-neighbour search
Suppose a knowledge base contains ten million document chunks.
Comparing a query against every stored vector can become expensive as the collection grows.
Vector-search systems often use approximate nearest-neighbour (ANN) indexes to find close matches efficiently without calculating every possible distance for every query.
Common indexing approaches include:
HNSW — Hierarchical Navigable Small World
A graph-based indexing method that organises vectors into navigable relationships. It is commonly used to provide fast similarity searches, with trade-offs involving memory, indexing time, and search parameters.
IVF — Inverted File Index
An approach that partitions vectors into groups or clusters and searches selected groups rather than the entire collection.
Product quantization
A technique that compresses vector representations to reduce memory requirements, potentially trading some search accuracy for efficiency.
Different databases offer different combinations of indexing methods and configuration options.
For many applications, approximate search is a good engineering trade-off. But approximation introduces another consideration: the nearest results returned by an index may not exactly match the true nearest neighbours.
Search quality should therefore be measured against representative queries, particularly when missing a relevant document would have significant consequences.
5. Why metadata filtering matters as much as similarity
Consider an organisation that stores documents for multiple projects.
Two documents may discuss the same technology, but one belongs to Project A and the other to Project B.
A vector search based only on semantic similarity might return both documents. Yet a user working on Project A may not be authorized to access the second document.
Metadata filters can restrict retrieval by attributes such as:
Project or organization.
Document type.
Approval status.
Effective date.
Product category.
User permissions.
For example, a query might search for the most relevant approved technical documents belonging to a particular project.
The application should enforce access permissions as part of the retrieval process, not rely on the language model to decide which documents are confidential.
Metadata quality is also important. If document versions or project identifiers are missing or incorrect, filtering cannot reliably enforce the intended rules.
For multi-tenant applications, tenant isolation must be designed and tested across the complete data path, including indexes, caches, document references, and background processing.
6. Vector search versus traditional keyword search
Vector search and keyword search solve related but different problems.
Keyword search is particularly useful when the user knows an exact identifier, phrase, part number, or error code.
Vector search is useful when the user describes a concept using different wording from the source document.
Consider a technical support application.
A user searches for an error code such as ERR-1042. An exact lexical match may be the best starting point.
Another user asks, “Why does the application stop responding after login?” The relevant troubleshooting document may use the phrase “session initialization timeout” rather than the user's wording. Semantic retrieval may help identify it.
This is why many applications use hybrid search, combining lexical and vector retrieval.
The two sets of results can be merged or reranked. Some systems use techniques such as Reciprocal Rank Fusion to combine rankings from different retrieval methods.
The best approach depends on the task. A technical documentation system may benefit from hybrid search, while another use case may work well with vector search alone.
The decision should be based on retrieval results rather than assumptions about which method is more advanced.
7. How vector databases fit into a RAG architecture
In a RAG application, a vector database is usually one component of a larger pipeline.
A simplified architecture looks like this:
Document ingestion
Documents are collected, parsed, cleaned, split into chunks, and associated with metadata.
Embedding generation
An embedding model converts the chunks into vectors.
Indexing
The vectors and their associated records are stored in a vector database or another system capable of vector search.
Query processing
When a user asks a question, the application generates a query embedding and searches for relevant chunks.
Retrieval and ranking
The application applies access filters, combines search results if necessary, and may re-rank the candidates.
Answer generation
A language model receives the selected context and generates an answer.
Source presentation
The application displays relevant citations or references so users can verify important claims.
Each stage can affect the final answer.
If the document parser loses a critical table heading, the embedding cannot recover the missing context. If retrieval selects an outdated specification, a powerful language model may still produce an incorrect answer.
The vector database is an important component, but it cannot compensate for every weakness in the surrounding architecture.
8. Choosing the right storage technology
A dedicated vector database is not always necessary.
The appropriate choice depends on data volume, query patterns, operational requirements, existing infrastructure, and the capabilities of the database already in use.
Some common options include:
PostgreSQL with pgvector
Useful when an application already uses PostgreSQL and wants vector search alongside relational data, SQL queries, and transactional application records.
Dedicated vector databases
Systems such as Qdrant, Milvus, and Weaviate provide vector-oriented indexing and search capabilities, with different deployment and operational characteristics.
Search platforms with vector capabilities
Platforms such as Elasticsearch and OpenSearch can combine conventional search with vector retrieval, which may be useful when an application already depends on them.
Managed cloud services
Managed offerings can reduce the operational burden of running indexes and infrastructure, although cost, data residency, access controls, and service limits still need consideration.
These are examples rather than a universal ranking.
Before selecting a technology, evaluate:
Expected vector count and embedding dimensions.
Required query latency and throughput.
Metadata-filtering capabilities.
Search accuracy and index configuration.
Update and deletion behavior.
Backup and recovery.
Hosting and data-location requirements.
Operational expertise and total cost.
A small application may be better served by a database extension than by introducing another service to maintain.
9. Common mistakes in vector-search implementations
Several issues appear repeatedly in practical implementations.
Using the wrong embedding model
An embedding model suited to general prose may perform poorly on specialized technical documents, multilingual content, or code-heavy material.
Choosing chunk sizes without testing
Chunks that are too small can lose context. Chunks that are too large may contain several unrelated topics and make retrieval less precise.
Assuming the highest similarity score guarantees relevance
A close vector match is a candidate, not proof that the content answers the question correctly.
Ignoring document updates
When source documents change, their indexed chunks and embeddings may need to be updated or removed. Otherwise, outdated information can remain searchable.
Using vector search for exact-value retrieval
For an authoritative current balance, inventory count, or transaction status, a direct database query may be more suitable than semantic similarity.
Skipping access-control testing
A technically accurate search engine can still expose confidential information if the application applies permissions incorrectly.
Optimizing latency before measuring relevance
A very fast search is of limited value if it repeatedly returns the wrong evidence.
10. Measure search quality before scaling
A vector-search system should be tested using realistic questions and known relevant documents.
Useful measurements include:
Recall@k: Does the result set contain the relevant documents within the top (k) results?
Precision@k: What proportion of the top results are relevant?
MRR: How highly ranked is the first relevant result?
Latency: How long does retrieval take?
Resource usage: How much memory, storage, and processing capacity is required?
Filter correctness: Does the system return only records the user is authorized to access?
Evaluate different embedding models, chunking approaches, index settings, and retrieval methods using the same test dataset wherever possible.
Also inspect individual failures. Aggregate metrics can hide a system that performs well on general questions but poorly on specialized identifiers or less common document types.
For RAG applications, evaluate retrieval quality separately from answer quality. This helps identify whether a failure comes from finding the wrong information or from the model misusing the correct information.
Conclusion
Vector databases are an important part of the modern AI engineering toolkit because they make semantic retrieval practical at scale.
But the real engineering challenge is not simply converting text into vectors and storing them.
It is choosing an appropriate embedding model, preserving document context, retrieving relevant information efficiently, applying access controls, keeping the index current, and measuring whether search results genuinely help users.
The key principle is simple:
A vector database helps find relevant information. The application must still determine whether that information is correct, current, authorized, and useful.
Start with a small evaluation dataset, measure retrieval quality, and select the simplest architecture that meets the application's actual requirements.
That approach is more reliable than choosing a technology because it is popular or assuming that semantic search automatically produces intelligent results.