# Vector database

A database that stores embeddings and finds the nearest ones fast. pgvector (Postgres), MongoDB Atlas Vector Search and Pinecone are common.

AI developers · Part 05: Embeddings + RAG · Card 4 of 14 · Last updated 2026-10-13

## Analogy

An index, but for meaning. Postgres with one extension and a new operator.

## Code example

`search.sql`

```sql
-- <=> is cosine distance in pgvector (smaller = closer)
SELECT content
FROM docs
ORDER BY embedding <=> $1
LIMIT 3;
```

## In an agent

It's the long-term library your agent searches. Postgres + pgvector can also hold memory and checkpoints.

## Practice

### Flashcards

- **What is a vector database?** A database that finds the nearest embeddings fast, like pgvector or Pinecone.

## Questions people ask

### Which vector database should a JavaScript developer use?

If you already run Postgres, start with the pgvector extension: one extension, one new column type, and your vectors live next to your normal data. MongoDB Atlas Vector Search and Pinecone are common alternatives. For learning and small projects, any of them is fine.

### What does a vector database actually do?

It stores embeddings with their text and finds the nearest ones to a query vector quickly, even across millions of rows. In pgvector you order by embedding <=> your query vector and take the top few. For an agent it is the long-term library that the search tool reads from.

## Related concepts

- [Embedding](https://studyvisually.com/learn/tech/ai-developers/embeddings-rag/embedding)
- [Cosine similarity](https://studyvisually.com/learn/tech/ai-developers/embeddings-rag/cosine-similarity)
- [Semantic search](https://studyvisually.com/learn/tech/ai-developers/embeddings-rag/semantic-search)
- [Metadata](https://studyvisually.com/learn/tech/ai-developers/embeddings-rag/chunk-metadata)

Web page: https://studyvisually.com/learn/tech/ai-developers/embeddings-rag/vector-database
Study this card in the app: https://studyvisually.com/app/learn?category=ai-developers&card=vector-database
