Tutorial

How to Build a RAG Pipeline with Citations Using Scavio

Build a RAG pipeline that emits citations the user can click. Scavio's typed JSON makes the citation step deterministic.

RAG citations fail when the LLM cannot tie a claim back to a source URL. Scavio's typed JSON gives every retrieved snippet a link field, making the citation step deterministic. This tutorial walks the build.

Prerequisites

  • Python 3.10+
  • Scavio API key
  • An LLM API key

Walkthrough

Step 1: Retrieve candidates

Scavio /search for the question.

Python
import os, requests
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}

def retrieve(q, n=8):
    r = requests.post('https://api.scavio.dev/api/v1/search', headers=H, json={'query': q}).json()
    return r.get('organic_results', [])[:n]

Step 2: Build a numbered source list

Each source has an index.

Python
def sources(results):
    return [(i, r['link'], r.get('snippet', '')) for i, r in enumerate(results, start=1)]

Step 3: Prompt the LLM with cite markers

Strict instruction.

Text
# Prompt:
# 'Answer the question using ONLY the provided sources.
#  Every claim must be followed by [N] where N is the source index.
#  Sources:
#  [1] {url}: {snippet}
#  [2] {url}: {snippet}
#  ...'

Step 4: Validate citation markers

Regex check before showing user.

Python
import re

def validate(answer, n_sources):
    cites = set(int(m) for m in re.findall(r'\[(\d+)\]', answer))
    return cites and max(cites) <= n_sources

Step 5: Render answer with linked citations

[1] becomes a clickable link.

Python
def render(answer, sources):
    out = answer
    for i, url, _ in sources:
        out = out.replace(f'[{i}]', f'[[{i}]]({url})')
    return out

Python Example

Python
# Per query: 1 Scavio call + 1 LLM call. Cost ~$0.005-0.02 depending on LLM.

JavaScript Example

JavaScript
// Same in TS.

Expected Output

JSON
User-facing answer with clickable citations. Each citation links to the original source, satisfying RAG trust requirements.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.10+. Scavio API key. An LLM API key. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Build a RAG pipeline that emits citations the user can click. Scavio's typed JSON makes the citation step deterministic.