EN ▾
Create key

ApiaiuncensoredUncensored AI RAG on Private Documents

Uncensored AI RAG on Private Documents

You can build a private question-answering tool over your own files with an uncensored AI and RAG on private documents, even though this API has no embeddings. Retrieval runs on your machine, and the model only sees the passages you choose to send.

Last updated

Summary

  1. RAG means retrieve passages first, then answer from them; the model never needs your whole archive.
  2. This API is text only with no embeddings, so retrieval is done locally with BM25 or a local embedding model.
  3. The selected passages do leave your machine in the prompt; prompts are not used for training.
  4. At 2,700 input and 350 output tokens, one answer costs $0.00058, about $0.58 per 1,000 questions.
A glass vault of glowing pages with a beam selecting three pages toward a server, representing private document RAG

What this setup does, and its privacy limit

People who search for uncensored ai rag private documents want one thing: ask questions of their own files without a model that balks at the content. RAG stands for retrieval-augmented generation. You split your documents into chunks, find the few chunks that match a question and paste them into the prompt with an instruction to answer only from them. The appeal here is that the model will work with sensitive, adult or otherwise awkward material without refusing, such as internal incident reports, legal drafts for lawful matters, your own fiction archive or research notes.

Be exact about privacy. Search and indexing run locally. But the retrieved passages travel to the API in the request, since the model has to read them. Prompts are not used for training on this service. If your rules say a document may never leave your machine, a hosted API is the wrong tool, and you need a model running on your own hardware. Strip or mask data you do not need to send.

Why retrieval is local here

The service is text only: chat completions, responses and a model list. It has no embeddings endpoint, no image or audio features and no fine-tuning. That is fine for RAG, because the retrieval step does not need to be a hosted service. You have two sensible options.

  • BM25 keyword ranking. A classic algorithm, available in Python as the rank_bm25 package. No model download, fast, and strong when questions share words with the documents.
  • A local embedding model. Packages such as sentence-transformers run on your own CPU or GPU and capture meaning better than keywords. They add a download and some compute.

The code below uses BM25 to keep the example short. You can swap the retriever later without touching the rest.

Step 1: Load and chunk the documents

Chunk size matters more than any other setting. Too small and answers lose context; too large and you waste tokens. Around 300 to 500 words with a small overlap works for most prose.

import pathlib

def load_chunks(folder, size=350, overlap=50):
    chunks = []
    for path in pathlib.Path(folder).rglob("*.txt"):
        words = path.read_text(encoding="utf-8", errors="ignore").split()
        step = size - overlap
        for start in range(0, max(len(words), 1), step):
            piece = " ".join(words[start:start + size])
            if piece:
                chunks.append({"source": path.name, "text": piece})
    return chunks

This reads plain text. For PDFs or Word files, extract the text first with a library of your choice, then feed it in the same way.

Step 2: Index and retrieve

Install the packages with pip install openai rank_bm25. BM25 works on tokenized text, so lowercase and split the chunks and the question the same way.

from rank_bm25 import BM25Okapi
import re

def tokenize(text):
    return re.findall(r"\w+", text.lower())

chunks = load_chunks("./docs")
bm25 = BM25Okapi([tokenize(c["text"]) for c in chunks])

def retrieve(question, k=6):
    scores = bm25.get_scores(tokenize(question))
    ranked = sorted(range(len(chunks)), key=lambda i: scores[i], reverse=True)
    return [chunks[i] for i in ranked[:k]]

Step 3: Ask the model, with sources

Number each passage so the model can cite it, and tell it what to do when the answer is not there. A low temperature keeps it close to the text.

import os
from openai import OpenAI

client = OpenAI(base_url="https://api.apiaiuncensored.com/v1", api_key=os.environ["API_KEY"])

def answer(question):
    hits = retrieve(question)
    context = "\n\n".join(
        "[%d] (%s) %s" % (i + 1, h["source"], h["text"]) for i, h in enumerate(hits)
    )
    resp = client.chat.completions.create(
        model="uncensored",
        temperature=0.2,
        max_tokens=500,
        messages=[
            {"role": "system", "content": (
                "Answer using only the numbered passages. Cite them like [2]. "
                "If the passages do not contain the answer, say so plainly."
            )},
            {"role": "user", "content": "Passages:\n" + context + "\n\nQuestion: " + question},
        ],
    )
    return resp.choices[0].message.content

print(answer("What did we decide about the vendor contract renewal?"))

Keep the base URL and the model name as shown. Get a key from the API key page, where new users can claim a $0.50 trial. Request fields are described in the docs.

Updating the index and handling real file types

Documents change. For a small corpus, rebuilding the BM25 index on startup takes seconds and avoids bugs. For a larger one, save the chunks to a JSON file along with each file's modified time, and re-chunk only files that changed.

  • PDFs. Extract text with a PDF library, and check a few pages by eye. Scanned pages need OCR first.
  • Tables. Plain text extraction can scramble columns. Convert tables to short sentences or CSV rows if the data matters.
  • Duplicates. Repeated chunks waste prompt space. Drop exact duplicates before indexing.
  • Sensitive fields. Mask names, account numbers or addresses that the question never needs, before the text goes into a prompt.

Tuning the quality

  • Retrieve more, then trim. Pull 10 chunks, show the top 6. If answers miss facts, raise k. The window is 100,000 tokens, so you have room.
  • Rewrite the question. Ask the model to turn a chat message like "and the second one?" into a standalone query before retrieval.
  • Add metadata. Put the file name and date in each chunk so that questions about time or source can match.
  • Try embeddings locally. If keyword ranking misses paraphrases, add a local embedding model and combine both scores.
  • Test with known answers. Write 20 questions whose answers you know and check the output after every change.

This model is tuned to answer without content refusals for lawful adult use. It still has a hard limit: no sexual content involving minors. As with any LLM, it can state something the passages do not support, so keep the citations visible and check the ones that matter. The earlier production checklist covers logging and failure handling.

A note on prompt injection

Documents can contain text that looks like instructions, for example a line in a pasted email that says to ignore the rules. The model may follow it. Mark the passages clearly as quoted material in the system message, tell the model to treat them as data, and avoid giving the pipeline tools that can change anything. For a read-only search tool this risk stays small, but it is worth one line in your system prompt.

When you can skip RAG

The context window is 100,000 tokens, prompt plus completion. If your whole corpus is a few dozen pages, you can paste it all into the prompt and skip retrieval. A 60,000-token corpus per question costs 60,000 x $0.15 / 1,000,000 = $0.009 in input, plus the output. That is about 15 times the cost of the $0.00058 RAG answer above, but it removes the risk that retrieval misses a passage.

A practical rule: use full-context for small, stable corpora and for questions that need the whole picture, such as summaries. Use RAG when the corpus is larger than the window, when cost per question matters, or when you want answers tied to specific passages. Either way, test with questions whose answers you already know.

Check the answers, not the pipeline

Keep a file of 20 questions with expected answers and the source file for each. After every change to chunk size, retriever or prompt, run all of them and count how many cite the right source. That count is more useful than any single impressive demo.

What it costs

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. Take six passages of about 400 tokens (2,400), plus 300 tokens of instructions and question, for 2,700 input tokens, and a 350-token answer:

  • Input: 2,700 x $0.15 / 1,000,000 = $0.000405
  • Output: 350 x $0.50 / 1,000,000 = $0.000175
  • Total: $0.00058 per question, or $0.58 per 1,000 questions.

Failed or refused requests are not charged. Credit is prepaid, never expires and is topped up in whole amounts from $20 to $500 using USDT on TRC20 or USDC on Base. Full keys allow 8 concurrent requests and 300 requests per minute, plenty for a team tool. See pricing for bonuses.

Common questions

Does this API provide embeddings for RAG?

No. It is text only, so do retrieval locally with BM25 or a local embedding model and send only the chosen passages to the chat endpoint.

Do my documents leave my machine?

The passages you put in the prompt do, because the model has to read them. Indexing and search stay local, and prompts are not used for training.

How many passages should I send?

Start with 5 to 8 chunks of 300 to 500 words. The context window is 100,000 tokens, so you can send more when answers need it.

How much does one answer cost?

With 2,700 input tokens and 350 output tokens it costs $0.00058, about $0.58 per 1,000 questions.

Get your API key now

Register, retrieve your key, update the base URL. Simple setup.