RAG

Free LLM API for RAG: chunking, embeddings and cost

RAG looks cheap until you count the tokens you resend. A single answer can carry five retrieved chunks, the chat history and a system prompt, so the free tier's daily token cap, not its requests-per-minute limit, decides how many questions you can answer.

Short answer. Embed once, store the vectors, retrieve four to six chunks, and send only those. On a 200K-token daily cap, a 3,500-token RAG request allows about 57 questions a day; on a 50K new-account cap, about 14.

The RAG token equation

One RAG request has four parts: the query embedding, the retrieved context, the conversation history and the answer. The generation call dominates. If you retrieve six chunks of 500 tokens each, the prompt is already 3,000 tokens before the system message and the question; add a 500-token answer and the request costs about 3,500 tokens.

That arithmetic explains most free-tier disappointment. A 200,000-token daily cap allows about 57 such requests; Plugsky's 250,000 ceiling allows about 71, and the 50,000 new-account allowance about 14.

Embeddings are the cheap part. Plugsky lists three embedding models with an 8K context, including a multilingual variant. OpenAI's text-embedding-3-small returns 1,536 dimensions by default and accepts up to 8,192 tokens per input. Embed each chunk once, store the vector with its source text, and never re-embed the corpus on every query.

Chunking that fits a free tier

Start with 300 to 600 tokens per chunk and 10 to 15% overlap. Smaller chunks make retrieval more precise but send more of them; larger chunks reduce the count but blur the topic. For a free tier, 400-token chunks and four retrieved passages is a better default than 1,000-token chunks and eight.

Keep structure. A chunk that starts mid-table or mid-code block is hard for the model to use, so split on headings and paragraphs first, then on token count. Store the document title, section heading, page number and source URL as metadata; those fields let the model cite and let you filter before retrieval.

Hybrid retrieval (BM25 plus vectors) usually improves recall at the same top-k. A reranker lets you retrieve ten candidates and send two or three.

A working retrieve-and-answer loop

This example keeps vectors in memory and uses cosine similarity. It is enough for a few thousand chunks; move to pgvector or another store when the corpus outgrows a process.

import math
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["PLUGSKY_API_KEY"],
    base_url="https://api.plugsky.com/v1",
)

def embed(texts: list[str]) -> list[list[float]]:
    resp = client.embeddings.create(model="plugsky-embed", input=texts)
    return [item.embedding for item in resp.data]

def cosine(a: list[float], b: list[float]) -> float:
    dot = sum(x * y for x, y in zip(a, b))
    na = math.sqrt(sum(x * x for x in a))
    nb = math.sqrt(sum(y * y for y in b))
    return dot / (na * nb) if na and nb else 0.0

def answer(query: str, chunks: list[str], vectors: list[list[float]], k: int = 4) -> str:
    q = embed([query])[0]
    ranked = sorted(range(len(chunks)), key=lambda i: cosine(q, vectors[i]), reverse=True)[:k]
    context = "\n\n".join(f"[{i}] {chunks[i]}" for i in ranked)
    resp = client.chat.completions.create(
        model="plugsky-lite",
        messages=[
            {"role": "system", "content": "Answer only from the context. Cite chunk numbers. Say 'not in the sources' when unsure."},
            {"role": "user", "content": f"Context:\n{context}\n\nQuestion: {query}"},
        ],
        max_tokens=400,
    )
    return resp.choices[0].message.content

Record the embedding model and dimension with every vector; mixing models produces meaningless scores. Hash each chunk and skip the embedding call when the hash exists.

Limits that break RAG

The free plan's 32K input cap is the first hard boundary. A prompt with 12 chunks, a long system message and history can cross it. The embedding model's 8K context is a second boundary: a longer chunk cannot be embedded, so split it first.

Tokens per minute matter more than requests per minute. Groq's free 8K TPM is smaller than a single 10K-token RAG prompt, so that request is rate-limited before it runs. Plugsky's free plan is more forgiving per request but still caps the day at 250,000 tokens, and paid plans raise the per-request input ceiling to 64K on Hobby, 128K on Starter and 256K on Builder.

The 262,144-token context on Plugsky's main models is not a licence to stuff documents; plan input caps still apply.

RAG decisionToken effectFree-tier recommendation
400-token chunks, top 4About 1,600 input tokensStart here
800-token chunks, top 6About 4,800 input tokensRerank down to 2-3
Send the full document20K to 100K tokensFails the 32K cap or the daily budget
Embed once, cache by hashZero repeat embeddingAlways do this
Hybrid search plus rerankExtra rerank call, fewer chunksUse when recall is poor

When free RAG stops working

Upgrade when seven-day usage passes 70% of the daily token cap, when p95 input crosses 16K tokens, or when users see 429s during normal traffic. Plugsky Hobby is $8 per month for 2 million tokens per day and 64K input per request; Starter is $20 for 5 million tokens and 128K input. Both are flat, so a spike in retrieved context does not produce a per-token bill.

If the corpus is small, retrieve fewer chunks and cache frequent answers; if it is large, the token budget is the product.

FAQ

Do I need a vector database for RAG?

Not for a small corpus. A list of vectors in memory, or a NumPy array, works for a few thousand chunks. Use pgvector or a dedicated store when you need persistence, filtering, concurrent writes or more chunks than a process can hold.

Which embedding model should I use?

Match the model to your language and retrieval task, record its dimension, and keep it fixed for the life of the index. Plugsky lists an 8K-context embedding model and a multilingual variant; OpenAI's text-embedding-3-small accepts 8,192 tokens and returns 1,536 dimensions by default.

Why does the model ignore my retrieved context?

The usual causes are poor recall, chunks that are too large or split mid-section, and a prompt that does not tell the model to refuse when the answer is absent. Measure recall at k before changing the generation model.

Can I use one free API for embeddings and chat?

Yes, if the provider serves both endpoints. Plugsky lists three embedding models alongside its chat models and exposes an OpenAI-compatible /v1/embeddings endpoint. Check that your plan includes the embedding model you choose.

Reviewed 20 November 2026. Primary sources checked 20 November 2026: OpenAI embeddings guide, Plugsky model catalogue, Plugsky pricing, Groq rate limits. Free-tier limits are published ceilings, not guarantees; confirm them in the provider console before capacity planning.