text of each record into a numeric vector so that semantically similar content sits close together in vector space. @ooneex/rag generates embeddings with OpenAI models — you pick the model in your vector database, and embedding happens automatically on add() and search().
Choosing a model
Declare the provider and model ingetEmbeddingModel():
openai. The available models:
| Model | Dimensions | Notes |
|---|---|---|
text-embedding-3-small | 1536 | Best price/performance — a strong default. |
text-embedding-3-large | 3072 | Highest quality; larger vectors, higher cost. |
text-embedding-ada-002 | 1536 | Previous-generation model, kept for compatibility. |
Configuration
Embeddings are generated through OpenAI, so set your API key in the environment:add() or search(), not at construction time.
How embedding works
You never compute or pass vectors yourself. When a table is created, the schema wires the embedding model into two roles:- The source field is
text— the column that gets embedded. - The vector field is
vector— where the generated embedding is stored and indexed.
- On
add(), thetextof each record is sent to the embedding model and the resulting vector is stored on the row. - On
search(), your query string is embedded with the same model and compared against stored vectors.
The embedding model is part of a table’s schema. Changing
getEmbeddingModel() after a table already exists does not re-embed existing rows — embed new data into a fresh table instead, then switch over.Where embeddings fit
Embeddings power the vector half of retrieval. At query time they are combined with a full-text search over the sametext and merged with an RRF reranker — see Search for how the two halves come together.