Embeddings
Embeddings allow you to convert text into vector representations, which are useful for semantic search, clustering, and similarity comparisons.
Setup
You need an embedding model. Ollama supports models like mxbai-embed-large or nomic-embed-text.
from mojentic.llm.gateways import EmbeddingsGateway
# Initialize gateway
gateway = EmbeddingsGateway(model="mxbai-embed-large")
Generating Embeddings
text = "The quick brown fox jumps over the lazy dog."
vector = gateway.embed(text)
print(vector[:5])
# => [0.123, -0.456, ...]
Batch Processing
You can embed multiple texts at once:
Cosine Similarity
Mojentic provides utilities to calculate similarity between vectors: