KnowledgeMemoryBlogPricingDocs Log in

How to Add a Knowledge Base to Your AI App in 3 Lines of Code

You don't need to build a RAG pipeline from scratch. No vector databases, no preprocessing strategies to tune, no inference models to manage. A production-ready knowledge base via a single API call.

You don't need to build a RAG pipeline. You don't need to set up vector databases, manage indexing, or run inference models yourself. You can add a production-ready knowledge base to your AI app with a single API call.

This tutorial shows you how to query a knowledge base using the Ragionex Context Engine API - in Python, Node.js, and cURL. The whole thing takes under a minute.

The 3-Line Version

Here is a complete knowledge base query. No SDK, no setup, no signup.

Python:

import requests

response = requests.post(
    "https://api.ragionex.com/v1/knowledge/search",
    headers={"X-API-Key": "rgx_knowledge_demo_geXuBZJ5O2GltcG63s1LGijGBwlERGlo"},
    json={"question": "How to format code?", "results": 10, "collection": "vscode-docs"}
)

print(response.json())

Node.js:

// Node.js 18+ (ES module: use .mjs or "type": "module" in package.json)
const response = await fetch("https://api.ragionex.com/v1/knowledge/search", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": "rgx_knowledge_demo_geXuBZJ5O2GltcG63s1LGijGBwlERGlo"
  },
  body: JSON.stringify({question: "How to format code?", results: 10, collection: "vscode-docs"})
});

const data = await response.json();
console.log(data);

cURL:

curl -X POST https://api.ragionex.com/v1/knowledge/search \
  -H "Content-Type: application/json" \
  -H "X-API-Key: rgx_knowledge_demo_geXuBZJ5O2GltcG63s1LGijGBwlERGlo" \
  -d '{"question": "How to format code?", "results": 10, "collection": "vscode-docs"}'

That is it. Copy any of those, run it, and you will get real answers from a VS Code documentation knowledge base. No account required.

What You Get Back

The API returns structured results with the answer content, the original source, and a unique ID:

{
  "success": true,
  "results": [
    {
      "answer": "VS Code has great support for source code formatting. The editor has two explicit format actions:\n\n- **Format Document** (`Shift+Alt+F`) - Format the entire active file.\n- **Format Selection** (`Ctrl+K Ctrl+F`) - Format the selected text.\n\nYou can invoke these from the Command Palette or the editor context menu.",
      "source": "https://raw.githubusercontent.com/microsoft/vscode-docs/37d415e5bb466264a5ada659fbece122b8ced902/docs/editor/codebasics.md",
      "id": "LE53LZWPN0"
    },
    {
      "answer": "The Default Formatter setting lets you choose which extension provides formatting for a given language. Type 'format' in the Settings search bar to see all formatter-related options...",
      "source": "https://raw.githubusercontent.com/microsoft/vscode-docs/37d415e5bb466264a5ada659fbece122b8ced902/docs/editor/codebasics.md",
      "id": "NOPPZI33CJ"
    }
  ]
}

Each result contains:

  • answer - The full markdown content answering your question, including images and code blocks from the original documentation
  • source - A direct link to the original source document, so users can verify the information
  • id - A unique identifier for each result

Step-by-Step Walkthrough

1. Get Your API Key (Free)

During Developer Preview, the API is free and open. Use this key:

rgx_knowledge_demo_geXuBZJ5O2GltcG63s1LGijGBwlERGlo

No signup, no credit card. Rate limited to 30 requests per minute. Just start making requests.

2. Make Your Request

Send a POST request to:

POST https://api.ragionex.com/v1/knowledge/search

With this JSON body:

{
  "question": "How to format code?",
  "results": 10,
  "collection": "vscode-docs"
}

Parameters:

Parameter Type Required Description
question string Yes Your search query (natural language)
results int No Number of results to return (1-50, default: 10)
collection string Yes The knowledge base collection to search

3. Parse the Response

The response is simple JSON. No pagination tokens, no cursor objects, no nested wrapper layers:

import requests

response = requests.post(
    "https://api.ragionex.com/v1/knowledge/search",
    headers={"X-API-Key": "rgx_knowledge_demo_geXuBZJ5O2GltcG63s1LGijGBwlERGlo"},
    json={"question": "How to debug Python?", "results": 5, "collection": "vscode-docs"},
    timeout=10
)
response.raise_for_status()
data = response.json()

for result in data["results"]:
    print(f"Source: {result['source']}")
    print(f"Answer: {result['answer'][:200]}")
    print("---")

Integrate Into Your AI App

The most common integration pattern combines Ragionex with your existing LLM. Ragionex retrieves the right context. Your LLM generates the answer using that verified source material, which significantly reduces hallucination risk compared to relying on the model's parametric memory alone.

Here is a complete example using OpenAI:

import requests
from openai import OpenAI

client = OpenAI()  # uses OPENAI_API_KEY env variable

def ask_with_knowledge(user_question):
    # Step 1: Get relevant context from Ragionex
    rag_response = requests.post(
        "https://api.ragionex.com/v1/knowledge/search",
        headers={"X-API-Key": "YOUR_RAGIONEX_API_KEY"},
        json={"question": user_question, "results": 5, "collection": "vscode-docs"},
        timeout=10
    )
    rag_response.raise_for_status()
    context = rag_response.json()

    # Step 2: Build context string from results
    knowledge = "\n\n---\n\n".join(
        f"Source: {r['source']}\n{r['answer']}"
        for r in context["results"]
    )

    # Step 3: Send to your LLM with the retrieved context
    completion = client.chat.completions.create(
        model="gpt-4o",
        messages=[
            {"role": "system", "content": f"Answer based ONLY on this context:\n\n{knowledge}"},
            {"role": "user", "content": user_question}
        ]
    )

    return completion.choices[0].message.content

# Usage
answer = ask_with_knowledge("How do I set up remote debugging?")
print(answer)

This pattern works with any LLM - OpenAI, Anthropic, Gemini, Mistral, or self-hosted models. Ragionex does not care what you do with the results. It just delivers the right context, fast.

Why this works better than stuffing documents into your prompt:

  • Ragionex returns only the relevant passages, not entire documents
  • Results are pre-ranked by relevance, so the best answer comes first
  • Each result includes its source, so you can pass citations to your users
  • Response time is under 200ms, so it does not slow down your LLM pipeline

Tips for Best Results

Use results: 10 for best accuracy. More results give your LLM more context to work with.

One topic per query. "How to format code?" works great. "How to format code and set up debugging and configure linting?" does not. Split compound questions into separate API calls.

Ask natural questions. The search is semantic, not keyword-based. "What happens when I press Ctrl+Shift+P?" works just as well as "command palette keyboard shortcut." Ask like you would ask a colleague.

Use the source field. Every result includes the original documentation URL. Display it to your users so they can read the full context. Trust goes up when users can verify answers.

Use Cases

Customer support bot - Connect your product documentation to Ragionex. When a customer asks a question, the bot retrieves the exact answer from your docs and responds with a source link. No more "I'll escalate this to a human" for questions that are already documented.

Internal knowledge base - Company wikis, SOPs, onboarding docs. Employees ask questions in natural language instead of searching through folders. The API returns the right section from the right document.

Documentation search - Replace basic keyword search on your docs site with semantic search. Users find what they need even when they don't know the exact terminology.

AI assistant with grounding - Any LLM-powered assistant that needs to stay factual. Feed Ragionex results as context to your LLM, and the model reasons over verified source material instead of its own parametric memory. Hallucination risk drops substantially because the answer is already there in the context.

Why Ragionex

Most knowledge base solutions require you to manage infrastructure, tune your own preprocessing, run inference at query time, and stitch the whole thing together. Ragionex handles all of that behind a single API endpoint.

  • Zero runtime AI cost - No LLM runs when you search. Retrieval is a pure lookup, so every query costs the same regardless of volume
  • Under 200ms response time - Fast enough to use in real-time chat applications without noticeable delay
  • Zero hallucination at the source layer - The API returns source material, not generated text. No generation step means no hallucination in the retrieval layer itself
  • No infrastructure - No databases to manage, no models to host, no GPUs to provision

The Developer Preview is live now with a VS Code documentation knowledge base. Try it free at ragionex.com - grab the API key and start querying in seconds.

For the architectural rationale - why retrieval is pure lookup with no LLM in the hot path - see Why We Don't Call an LLM at Query Time. Building an AI coding agent that also needs persistent memory between sessions? That is a separate primitive with the same shape - see Add Persistent Memory to Cursor, Claude Code, and Windsurf in 3 Lines.


Have questions? Join the Ragionex Discord or email [email protected].

Ready to try it?

Free API key. No credit card. Start using in seconds.

Get Started