A chat model only knows what is in its request. RAG — Retrieval-Augmented Generation — means first retrieving, from a corpus, the passages that answer the question, then placing them in the prompt. Embeddings are the component that makes this search possible: each passage becomes a vector, and two close texts have close vectors.
What the API serves today
The POST /v1/embeddings route exists and follows the OpenAI contract. It is not served yet: the current catalogue contains no model with the embeddings capability, and the documentation marks the endpoint as not served. In practice, GET /v1/models returns chat models only, with their capabilities (chat, tools, reasoning); calling /v1/embeddings with one of them produces no vector.
The pipeline below therefore computes vectors locally with BGE-M3 — an open-weight, multilingual embedding model under the MIT licence — and uses the Effrenus API only for generation. Nothing prevents an embeddings model from being added later: the request and response shape would remain OpenAI's, with an input field, a model field, a data[].embedding list in return and input-only billing.
Chunking the documents
Chunking decides the quality of the search. A fixed 500-character window breaks sentences and mixes topics; following the document structure works better.
- One chunk carries one idea: a section, a paragraph, a FAQ entry.
- Aim for 400 to 800 tokens, with 10 to 15% overlap between neighbouring chunks.
- Keep the metadata: source, URL, section title, date, page number.
- Handle tables and code blocks separately: they survive plain-text splitting badly.
- Strip navigation, footers and repeated mentions, which pollute the search.
A chunk without metadata is an orphan vector: the model will know what to say, but not where it comes from.
Embedding with BGE-M3
BGE-M3 encodes the question and the documents with the same model; that symmetry is what makes cosine similarity useful. The computation takes a few lines.
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("BAAI/bge-m3")
vectors = model.encode(
[chunk["text"] for chunk in chunks],
batch_size=16,
normalize_embeddings=True,
)
Normalisation brings every vector to a length of 1: the dot product is then enough to rank passages. BGE-M3's dense version produces 1,024 dimensions.
Store each vector with its metadata in the database that fits your scale: pgvector if PostgreSQL is already there, sqlite-vec for a prototype, Qdrant or LanceDB for a dedicated service.
Retrieve, then generate
The question goes through the same transformation, then you ask for the k nearest passages. Eight is a reasonable starting point; the prompt must make the sources visible.
import httpx
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("BAAI/bge-m3")
question = "How long are logs retained?"
qv = model.encode([question], normalize_embeddings=True)[0]
# pgvector: ORDER BY vector <=> %s::vector LIMIT 8
passages = search(qv, k=8)
context = "\n\n".join(
f"[{i + 1}] {p['section']} — {p['text']}" for i, p in enumerate(passages)
)
prompt = (
"Answer only from the excerpts below. "
"Cite the number of every excerpt you use. "
"If the information is missing, say so.\n\n"
+ context + "\n\nQuestion: " + question
)
r = httpx.post(
"https://api.effrenus.com/v1/chat/completions",
headers={"Authorization": f"Bearer {KEY}"}, # Effrenus API key
json={"model": "effrenus-auto", "temperature": 0.2, "max_tokens": 700,
"messages": [{"role": "user", "content": prompt}]},
timeout=120,
)
print(r.json()["choices"][0]["message"]["content"])
print(r.headers.get("x-ef-cost-micro"))
Three settings matter more than the rest: an instruction that forbids going beyond the excerpts, numbered sources so the citation can be checked, and a bounded max_tokens. The model picked from the catalogue needs a window wide enough for the injected context; effrenus-auto routes to a light or heavy target depending on the request.
Checking and bounding
A RAG pipeline is measured before it goes to production. Build about twenty questions whose answer and source passage you know, then check that the right chunk appears in the top 8. If it does not, the problem lies in the chunking or the metadata before it lies in the generation model.
In operations, log the question, the identifiers of the retrieved passages and the answer. The x-ef-cost-micro header gives the cost of each call, GET /v1/me gives the balance and the latest requests. Per-token billing makes a RAG pipeline's cost proportional to the size of the injected context: going from eight to four passages halves the input bill, at the price of lower recall.
The limits remain real. BGE-M3 run locally uses your CPU or GPU and does not follow the service's updates; changing embedding model means recomputing the index. RAG reduces invented answers, it does not remove them: outside the corpus, the right answer is "I don't know", not a plausible sentence. And as long as no embeddings model is served by the API, the index stays with you.
For the exact route and header contract, see the documentation; for served models and their capabilities, the catalogue; for per-token billing, the pricing page.