๐Ÿ“ LLM & AI

Embeddings: Coordinates of Text in Semantic Space

P
Author
PyLand Team
๐Ÿ“…
Published
30.06.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
298
๐ŸŒณ
Level
Advanced

An embedding is a numerical vector that represents a piece of text. Texts that are similar in meaning get vectors that are close to each other. This is the foundation of semantic search in RAG systems.

Analogy

Imagine a space with coordinates. Each word is a point:
- “cat” and “kitten” โ€” nearly in the same spot
- “cat” and “automobile” โ€” far apart
- “Python” and “programming” โ€” close together

An embedding is exactly those coordinates in such a space, just with hundreds of dimensions.

How ChromaDB creates embeddings

ChromaDB automatically creates embeddings during add() using the built-in all-MiniLM-L6-v2 model:

import chromadb

collection = chromadb.PersistentClient("./db").get_or_create_collection("docs")

# ChromaDB computes embeddings for each text automatically
collection.add(
    documents=["Python is a programming language", "The cat is sitting on the sofa"],
    ids=["doc_0", "doc_1"]
)

# During search, the query is also turned into an embedding
results = collection.query(
    query_texts=["How do I start programming?"],
    n_results=1
)
# Returns "Python is a programming language" as the closest match

Cosine distance

ChromaDB uses cosine distance (0 to 2):

distance = 0.0  โ†’ texts are identical
distance = 0.3  โ†’ very similar (relevance ~70%)
distance = 0.7  โ†’ weak connection
distance = 2.0  โ†’ opposite in meaning
results = collection.query(query_texts=["question"], n_results=5, include=["distances"])
for dist in results["distances"][0]:
    relevance = 1 - dist
    print(f"Relevance: {relevance:.1%}")
Question: "How do I write a function?"
Text:     "def lets you declare a subroutine in Python"

With keyword search โ€” no matches. With semantic search โ€” high relevance, because the meanings are close.

Limitations of ChromaDB’s built-in model

  • The all-MiniLM-L6-v2 model handles English better than other languages
  • For better quality with non-English text: OpenAI text-embedding-3-small or text-embedding-ada-002
# Example with OpenAI embeddings (for reference)
import chromadb
from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction

ef = OpenAIEmbeddingFunction(api_key="sk-...", model_name="text-embedding-3-small")
collection = client.get_or_create_collection("docs", embedding_function=ef)

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

AI Agents: ReAct Loop and Autonomous Actions

A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 334
๐Ÿ“

Pydantic v2: Data Validation in Python

Pydantic validates and converts data through type annotations. It is commonly used in APIs and...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 327
๐Ÿ“

asyncio in Python: Asynchronous Programming

asyncio is Python's standard library for asynchronous code. It lets you execute multiple tasks "simultaneously"...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 317
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Neural Networks in Code: 5 AI Projects in Python with Claude Open course curriculum