What it is
Embeddings convert text into numerical vectors (typically []float32) that preserve semantic similarity.
Once you have vectors, you can do things like similarity search, clustering, deduplication, and retrieval.
In Phero, embeddings are a building block you combine with a vector store and the RAG engine.
Provider implementations live in subpackages (for example, embedding/openai).
Basic usage
You typically embed either user queries or document chunks. In the RAG examples, text is split into chunks and then embedded before it’s stored in a vector store.
// From examples/rag-chatbot (edited for brevity)
splitter := textsplitter.NewRecursiveCharacterTextSplitter(chunkSize, chunkOverlap)
chunks := splitter.SplitText(string(fileBytes))
// Embed a chunk (or a query) to get vectors
vecs, err := embedder.Embed(ctx, []string{chunks[0]})
if err != nil {
// handle error
}
_ = vecs // []embedding.Vector (typically []float32)
Example: infer vector size (RAG + vector stores)
Many vector stores require a fixed vector dimension for a collection/index. The RAG Chatbot and Long-Term Memory examples infer the dimension from the embedder by embedding a probe text.
// From examples/rag-chatbot and examples/long-term-memory (edited for brevity)
// Qdrant collections require a fixed vector size. Infer it from the embedder.
vecs, err := embedder.Embed(ctx, []string{"vector size probe"})
if err != nil {
// handle error
}
if len(vecs) != 1 || len(vecs[0]) == 0 {
// handle error
}
vectorSize := uint64(len(vecs[0]))
Using embeddings in Phero
Embeddings are usually combined with a vector store to power RAG:
- Split documents into chunks (
textsplitter) - Embed each chunk (
embedding) - Store/search vectors (
vectorstore) - Retrieve top-k matches per query (
rag)
See the examples: RAG Chatbot and Long-Term Memory.
Run an example
These examples exercise embeddings as part of a full retrieval pipeline. Follow each example’s README for any required services and provider setup.
# from repo root
go run ./examples/rag-chatbot -file ./README.md
go run ./examples/long-term-memory
Related packages
- rag: end-to-end retrieval pipeline
- vectorstore: store/search vectors
- textsplitter: chunk documents for ingestion
- memory: conversational memory (some implementations use embeddings indirectly)