Answer strategies implement Retrieval-Augmented Generation (RAG) to answer user questions using documentation search and LLM inference.
Each answer strategy follows this general pattern:
The active strategy is selected in answer/index.ts by uncommenting the desired import.
llama-3.3-70b-default - Default strategy using Llama 3.3 70B
llama-3.3-70b-versatileBest for: General purpose Q&A with good balance of quality and speed
llama-3.3-70b-versatileConfiguration options:
{
limit: 10, // Search results to consider
minScore: 0, // Minimum search score
maxContextPages: 5, // Pages to include in context
temperature: 0.3, // LLM temperature
model: "llama-3.3-70b-versatile" // Override model
}
To create a new answer strategy:
/answer/ (e.g., llama-3.1-8b-fast.ts)AnswerStrategy interface:import type { AnswerStrategy, AnswerResult, AnswerOptions } from "./types.ts";
export const answerStrategy: AnswerStrategy = {
name: "your-strategy-name",
description: "Brief description of your strategy",
answer: async (query: string, options: AnswerOptions = {}): Promise<AnswerResult> => {
// Your implementation here
// 1. Search for relevant pages
// 2. Get full content
// 3. Format as context
// 4. Call LLM
// 5. Return AnswerResult
},
};
answer/index.ts and comment out other strategiesHere are some ideas for additional strategies you might want to implement:
GET /answer?q=How+do+I+use+the+Groq+API
GET /answer?q=What+models+are+available&maxContextPages=3&temperature=0.5
GET /answer/info
{ "answer": "markdown formatted answer", "query": "user's original question", "searchResults": [ { "path": "api/reference", "url": "https://...", "title": "API Reference", "score": 95.2 } ], "contextUsed": 5, "totalTokens": 8500, "metadata": { "strategy": "llama-3.3-70b-default", "model": "llama-3.3-70b-versatile", "temperature": 0.3, "searchResultsCount": 10, "timings": { "search": 45.2, "contextPrep": 5.1, "llm": 1250.3, "total": 1300.6 } } }
Match model to task:
System prompts matter:
Manage context window:
Error handling:
Post-processing:
cleanupMarkdownLinks() to remove .md extensions from generated linksAnswers automatically clean up markdown links to remove .md extensions:
// Before cleanup
[Compound](https://console.groq.com/docs/agentic-tooling/compound-beta.md)
// After cleanup
[Compound](https://console.groq.com/docs/agentic-tooling/compound-beta)
This happens through:
cleanupMarkdownLinks() function removes any remaining .md extensionsTo disable cleanup (not recommended):
// In your custom strategy, skip the cleanup:
return {
answer: llmResponse, // Don't call cleanupMarkdownLinks()
// ... rest of result
};
Test your strategy with various question types:
Target performance for answer strategies:
Strategies taking >5s should be optimized or marked as "detailed" mode.