> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bindai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 05.3 embeddings

# Embeddings

Embeddings are numerical representations of text that allow BindAI to perform **semantic search** instead of simple keyword matching.

Rather than searching for exact words, embeddings capture the meaning of text, making it possible to retrieve relevant information even when different wording is used.

Embeddings are a core component of Retrieval-Augmented Generation (RAG).

***

# What is an Embedding?

An embedding converts text into a high-dimensional vector.

Conceptually:

```text id="g8k2yv" theme={null}
"The server is offline."

↓

Embedding Model

↓

[0.12, -0.48, 0.73, ...]
```

Although the vector itself is not human-readable, similar pieces of text produce vectors that are close together in vector space.

***

# Why Embeddings?

Traditional keyword search depends on exact matches.

Example:

Document:

```text id="k5z9qa" theme={null}
The application crashed unexpectedly.
```

User asks:

```text id="n3u8xd" theme={null}
Why did the program fail?
```

Keyword search may fail because the words differ.

Embedding search recognizes that **crashed** and **failed** are semantically related.

***

# Semantic Search

Embedding search works by comparing vector similarity.

```text id="d7r4mp" theme={null}
User Question

↓

Embedding

↓

Vector Search

↓

Most Similar Documents
```

This allows the retrieval system to find information based on meaning rather than wording.

***

# Embedding Pipeline

A typical embedding workflow looks like this.

```text id="v6c1tx" theme={null}
Document

↓

Chunking

↓

Embedding Model

↓

Vector Database

↓

Semantic Search
```

When users ask questions, the same embedding model converts the query into a vector for comparison.

***

# Query Example

Documents contain:

```text id="b4y7kn" theme={null}
How to reset a password.
```

The user asks:

```text id="p2m6wf" theme={null}
I forgot my login credentials.
```

Although the wording differs, embeddings recognize that both relate to account access and password recovery.

***

# Similarity Search

Once vectors are generated, BindAI compares them using similarity metrics.

Conceptually:

```text id="q8t5lr" theme={null}
Query Vector

↓

Compare

↓

Document A

Document B

Document C

↓

Top Matches
```

Only the most similar documents are retrieved.

***

# Embedding Models

Different providers offer embedding models optimized for different tasks.

Examples include:

* OpenAI embedding models
* Azure OpenAI embeddings
* Cohere embeddings
* Hugging Face models
* Local embedding models

BindAI is designed so embedding providers can be replaced without changing the retrieval pipeline.

***

# Document Embeddings

Documents are embedded only once during indexing.

```text id="m9p3ec" theme={null}
Documents

↓

Generate Embeddings

↓

Store Vectors
```

This preprocessing step makes later searches much faster.

***

# Query Embeddings

Each user question is embedded at runtime.

```text id="r4n8zb" theme={null}
User Question

↓

Generate Embedding

↓

Vector Search
```

The resulting vector is compared against previously stored document vectors.

***

# Vector Databases

Embeddings are commonly stored in vector databases.

Examples include:

* Pinecone
* Qdrant
* Chroma
* Weaviate
* Milvus
* pgvector
* Redis Vector Search

These databases are optimized for fast similarity searches across large collections of vectors.

***

# Embeddings vs Keywords

| Keyword Search   | Embedding Search                        |
| ---------------- | --------------------------------------- |
| Exact words      | Meaning                                 |
| Limited synonyms | Understands related concepts            |
| Literal matching | Semantic matching                       |
| Fast             | Slightly more computationally expensive |
| Less flexible    | More accurate for natural language      |

Embedding search generally produces better retrieval quality for AI assistants.

***

# Choosing an Embedding Model

When selecting an embedding model, consider:

* retrieval accuracy
* language support
* vector dimensions
* inference speed
* hosting requirements
* cost
* compatibility with your vector database

The best choice depends on your application and deployment environment.

***

# Best Practices

* Generate embeddings only after documents are finalized.
* Rebuild embeddings when documents change significantly.
* Use the same embedding model for indexing and querying.
* Store document metadata alongside vectors.
* Combine embeddings with metadata filters when appropriate.
* Chunk large documents before generating embeddings.

***

# Summary

Embeddings transform text into semantic vector representations that make intelligent retrieval possible.

By searching for meaning instead of exact keywords, BindAI can locate relevant information even when users phrase questions differently from the original documents, significantly improving the quality of Retrieval-Augmented Generation.
