Retrieval-augmented generation (RAG) pairs a search retrieval step with an LLM generation step. The Andi API handles retrieval — you pass the results as context to the LLM, which generates answers grounded in real web sources.
How it works
- User asks a question
- Your app searches the web via the Andi API
- Search results become context for the LLM prompt
- The LLM generates an answer grounded in those results
Complete example
# Step 1: Search
results=$(curl -s \
"https://search-api.andisearch.com/api/v1/search?q=what+causes+aurora+borealis&extracts=true&limit=5" \
-H "x-api-key: $ANDI_API_KEY")
# Step 2: Format context (extract titles and descriptions)
context=$(echo "$results" | jq -r '.results[] | "[\(.title)](\(.link))\n\(.desc)\n"')
echo "Context for LLM:"
echo "$context"
# Step 3: Pass $context to your LLM of choice
Using format=context
For simpler RAG setups, use format=context to get results pre-formatted as markdown. This skips the manual formatting step:
response = requests.get(
"https://search-api.andisearch.com/api/v1/search",
params={
"q": "what causes aurora borealis",
"format": "context",
"limit": 5,
},
headers={"x-api-key": api_key},
)
# Response is markdown text — pass directly to your LLM
context = response.text
format=context is the fastest path to a working RAG pipeline. Use format=json with extracts=true when you need more control over how context is structured.
Using deep search for RAG
For research-heavy queries, deep search provides broader source coverage and spell correction:
response = requests.get(
"https://search-api.andisearch.com/api/v1/search",
params={
"q": "what causes aurora borealis",
"depth": "deep",
"extracts": "true",
"limit": 10,
},
headers={"x-api-key": api_key},
)
Deep search takes ~2-3 seconds vs ~1 second for fast search. Use it when answer quality matters more than latency.
Tips for better RAG results
- Use
extracts=true to get longer text passages beyond the short desc field
- Set
limit=5 to limit=10 — more results give the LLM more context to draw from, but too many can dilute relevance
- Include source URLs in the prompt so the LLM can cite them
- Use
includeDomains to restrict to authoritative sources for domain-specific questions
- Tell the LLM to say “I don’t know” when the search results don’t contain the answer
Next steps