Use case
RAG and search
Retrieval-augmented generation answers questions from your own documents. Your retrieval layer finds the relevant passages; a model reads them and writes an answer that cites where each claim came from.
The problem
A model on its own doesn't know your internal docs, and when it doesn't know, it tends to guess. Pasting every document into the prompt is expensive and still misses things. RAG narrows the prompt to the few passages that matter and asks the model to answer only from them.
How it works with NeuronGate
01
Question
From a user or a search box
02
Your retrieval
Vector store, keyword search or both
03
Top passages
Numbered, with source ids
04
Generation
Chat completion with the passages in the prompt
05
Cited answer
Claims mapped back to sources
Keep your embedding model and vector store where they are. NeuronGate takes the generation step, which is where the model choice matters most and where you'll want to try several models against each other.
Choosing models
The generator needs to follow "answer only from these sources" and to handle the size of your retrieved context. Context windows and prices are listed in the model catalog.
| Role | Good fit | Why | Trade-off |
|---|---|---|---|
| Answer generation | ~anthropic/claude-sonnet-latest | Sticks to the provided sources and cites carefully | Higher price per answer |
| High-volume search answers | ~google/gemini-flash-latest | Fast and inexpensive, with a large context window | Check citation accuracy on your data |
| Query rewriting | deepseek/deepseek-v4-flash | Cheap for turning a chatty question into a search query | Adds one call of latency |
| Long documents | ~google/gemini-flash-latest | Fits whole documents when chunking loses the thread | Long prompts cost more per request |
Example: a cited answer
search() stands in for your retrieval layer. The prompt numbers each passage so the model can cite [1], [2] and your UI can link them.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://neurongate.net/v1",
api_key=os.environ["NEURONGATE_API_KEY"],
)
def answer(question: str) -> str:
passages = search(question, k=6) # your vector store / search index
sources = "\n\n".join(
f"[{i}] ({p.doc_id}) {p.text}" for i, p in enumerate(passages, start=1)
)
reply = client.chat.completions.create(
model="~anthropic/claude-sonnet-latest",
temperature=0,
messages=[
{"role": "system", "content": (
"Answer using only the numbered sources. Cite them like [1]. "
"If the sources don't contain the answer, say you don't know."
)},
{"role": "user", "content": f"Sources:\n{sources}\n\nQuestion: {question}"},
],
)
return reply.choices[0].message.contentRetrieval quality beats model size
Documents can carry instructions
Cost control
In RAG, retrieved passages are most of the input tokens. Send fewer, better passages: six well-chosen chunks usually beat twenty loosely related ones on both cost and accuracy.
- 1
Give the workload its own key
Create a key just for search answers under API keys. Its usage then shows up separately in the logs, and revoking it touches nothing else. - 2
Set a monthly spend cap
Once the key has spent its cap for the month, its requests are refused until the next month or until you raise the cap. Size it from a week of real traffic, not a guess. - 3
Allowlist the models it may call
Restrict the key to the models this workload actually uses, for example~anthropic/claude-sonnet-latestanddeepseek/deepseek-v4-flash. A typo or a prompt-injected model switch then fails instead of quietly running on a pricier model. - 4
Watch the logs
Filter the request log by this key to see tokens, cost and latency per call. Export CSV for a monthly cost-per-workload report.
FAQ
Do I have to move my vector database?
No. Retrieval stays in your stack. NeuronGate is the OpenAI-compatible endpoint for the generation step, so only the chat completion call changes.
Will my documents be stored?
No. The passages you send are part of the request; NeuronGate logs request metadata (model, tokens, cost, latency, status), not the content.
How do I compare generator models on my data?
Run the same questions and passages through two or three models with one key, then compare answers and costs. The model evaluation guide shows the setup.