Paper was never my biggest problem. Finding a document again was.
Invoices, contracts, official letters, meeting notes — they're all digital now, but file names are terrible memory aids. I usually remember what a document said, not what I called the PDF.
That's why I started building my personal AI Office. Paperless-ngx handles OCR, filing and the originals. A separate AI layer extracts meaning, generates summaries and tags, builds a semantic index, and lets me ask questions about the collection. The core archive stays on my own infrastructure.

The goal: Less hunting through folders. More asking my documents directly.
Architecture
I keep the responsibilities deliberately separate:
- A scanner or an upload sends a document to Paperless-ngx.
- Paperless performs OCR, stores the original and manages metadata.
- A small integration retrieves document text through the API.
- The AI pipeline processes the text and creates embeddings.
- A vector database stores those embeddings.
- A retrieval-augmented generation (RAG) API finds relevant passages before answering questions.
Paperless is still the system of record; the AI index is something I can rebuild. That's an important distinction when the archive contains private documents.
Paperless as the foundation
Paperless-ngx imports documents, performs OCR and makes the archive searchable. The example below is a deliberately simple Docker Compose starting point with Redis, PostgreSQL and the Paperless web service.
A production deployment needs additional care: replace example credentials, use a secret store or protected environment file, secure network access, configure all required Paperless settings, pin/test versions, and back up the database and media. The literal password in this illustrative Compose file is not a password to reuse.
The consume directory is useful: anything a scanner, mail rule or automation places there can be picked up for import.
version: "3.8"
services:
redis:
image: redis:7
restart: unless-stopped
db:
image: postgres:15
restart: unless-stopped
environment:
POSTGRES_DB: paperless
POSTGRES_USER: paperless
POSTGRES_PASSWORD: paperless
webserver:
image: ghcr.io/paperless-ngx/paperless-ngx:latest
restart: unless-stopped
depends_on:
- redis
- db
ports:
- 8000:8000
environment:
PAPERLESS_REDIS: redis://redis:6379
PAPERLESS_DBHOST: db
PAPERLESS_DBNAME: paperless
PAPERLESS_DBUSER: paperless
PAPERLESS_DBPASS: paperless
volumes:
- type: bind
source: ./data
target: /usr/src/paperless/data
- ./media:/usr/src/paperless/media
- ./consume:/usr/src/paperless/consume
Reading document content through the API
The AI pipeline needs OCR text. Paperless exposes document records through an API. This short Python example authenticates with a token, asks for documents and prints each document's title and extracted text.
It's an illustrative snippet, not a complete exporter: a real one must handle pagination, timeouts, errors and the relevant access permissions. Never hardcode a real API token in a published script.
import requests
URL = "http://paperless:8000/api/documents/"
TOKEN = "API_TOKEN"
headers = {
"Authorization": f"Token {TOKEN}"
}
r = requests.get(URL, headers=headers)
for doc in r.json()["results"]:
print(doc["title"], doc["content"])
Configuring the AI environment
I keep the connection details, storage path and model choices in one settings module. Tokens and API credentials come from an environment file rather than being pasted directly into application code.
The example uses an embedding model for the semantic index and a chat model for responses. Those are configuration choices, not permanent requirements — model availability and cost can change.
One privacy trade-off is easy to miss: sending document text to a hosted API sends that content outside your self-hosted infrastructure. Decide what is allowed before indexing contracts, personal records or business documents. Local processing is an alternative if that matters more than convenience.
import os
from dotenv import load_dotenv
load_dotenv()
PAPERLESS_URL = os.getenv("PAPERLESS_URL")
PAPERLESS_TOKEN = os.getenv("PAPERLESS_TOKEN")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
CHROMA_PATH = os.getenv("CHROMA_PATH", "./vector_db")
EMBEDDING_MODEL = "text-embedding-3-small"
CHAT_MODEL = "gpt-4o-mini"
PAPERLESS_URL=http://paperless:8000
PAPERLESS_TOKEN=
OPENAI_API_KEY=
CHROMA_PATH=./vector_db
Building the semantic index
The first AI step is splitting each OCR text into smaller passages. An embedding model turns those passages into numeric vectors representing their meaning. I store those vectors in a local Chroma database so related passages can be found without knowing the exact wording.
The Python sample below shows the basic idea: fetch a document, split it into chunks, create embeddings and add them to the collection.
It is intentionally minimal. An operational indexer should use stable IDs, update or remove obsolete chunks, deal with duplicates and limit access to confidential material. The example assumes the document-export helper is implemented elsewhere.
from openai import OpenAI
import chromadb
from scripts.export_documents import get_documents
from config.settings import *
client = OpenAI(api_key=OPENAI_API_KEY)
chroma = chromadb.PersistentClient(path=CHROMA_PATH)
collection = chroma.get_or_create_collection("documents")
def split_text(text, size=500):
words = text.split()
for i in range(0, len(words), size):
yield " ".join(words[i:i+size])
def index_document(doc):
text = doc["content"]
chunks = list(split_text(text))
for i, chunk in enumerate(chunks):
emb = client.embeddings.create(
model=EMBEDDING_MODEL,
input=chunk
)
collection.add(
ids=[f"{doc['id']}_{i}"],
documents=[chunk],
embeddings=[emb.data[0].embedding]
)
mkdir vector_db
Automatic summaries
A newly imported document can also receive a short summary. The sample sends the document text to the configured model and asks for three sentences.
In a real setup I would add length limits, error handling and an instruction to treat the document as untrusted input. Documents can contain text that looks like instructions, but those instructions must not control the assistant or its tools.
from openai import OpenAI
from config.settings import *
client = OpenAI(api_key=OPENAI_API_KEY)
def summarize(text):
prompt = f"""
Fasse dieses Dokument in drei Sätzen zusammen.
{text}
"""
r = client.chat.completions.create(
model=CHAT_MODEL,
messages=[{"role":"user","content":prompt}]
)
return r.choices[0].message.content
Automatic tags
The same principle works for tagging. I ask the model for up to five short tags and parse its answer into a list.
I would validate the output before sending it back to Paperless: deduplicate tags, check which ones actually exist, and avoid uncontrolled proliferation of near-identical labels. This snippet demonstrates generation, not the complete Paperless write-back.
from openai import OpenAI
from config.settings import *
client = OpenAI(api_key=OPENAI_API_KEY)
def generate_tags(text):
prompt = f"""
Analysiere das Dokument und gib maximal fünf Tags zurück.
Nur einzelne Wörter.
{text}
"""
r = client.chat.completions.create(
model=CHAT_MODEL,
messages=[{"role":"user","content":prompt}]
)
tags = r.choices[0].message.content
return [t.strip() for t in tags.split("\n") if t.strip()]
Asking questions across the archive
This is my favorite part. RAG — retrieval-augmented generation — combines search with a language model.
A question is embedded, Chroma returns related passages, and the model uses those passages to draft a reply. The FastAPI example below shows that flow, followed by the command that starts the API.
It's a prototype, not a secure public-facing document service. Before exposing it, add authentication and per-user document permissions, protect it from prompt injection, cite retrieved source documents, and ensure it can say “I don't know” when the evidence isn't there. A naive top-five similarity search can produce plausible but wrong answers.
from fastapi import FastAPI
import chromadb
from openai import OpenAI
from config.settings import *
app = FastAPI()
client = OpenAI(api_key=OPENAI_API_KEY)
chroma = chromadb.PersistentClient(path=CHROMA_PATH)
collection = chroma.get_collection("documents")
@app.get("/ask")
def ask(q: str):
emb = client.embeddings.create(
model=EMBEDDING_MODEL,
input=q
)
results = collection.query(
query_embeddings=[emb.data[0].embedding],
n_results=5
)
context = "\n".join(results["documents"][0])
prompt = f"""
Nutze diese Dokumente um die Frage zu beantworten.
{context}
Frage: {q}
"""
answer = client.chat.completions.create(
model=CHAT_MODEL,
messages=[{"role":"user","content":prompt}]
)
return {
"answer": answer.choices[0].message.content
}
uvicorn api.rag_api:app --host 0.0.0.0 --port 9000
Keeping the index fresh
A scheduled task can refresh the vector index overnight. The example uses a 3 a.m. cron job.
As written, that assumes a working index_documents.py entry point and the right Python environment. It also needs incremental updates or duplicate protection in a real deployment — otherwise repeated indexing can waste resources or fail on existing IDs.
0 3 * * * python3 /srv/paperless_ai/scripts/index_documents.py
The result
With the pieces connected, I end up with a document archive that does more than store files. It can import, OCR, classify, summarize, tag and retrieve relevant passages.
The kinds of questions I want to ask are straightforward:
- Which invoices did I receive from my electricity supplier?
- When was the heating last serviced?
- Which documents relate to my building insurance?
And, crucially, I want answers tied back to the actual documents so I can check them.
Conclusion
Paperless solves the archiving problem. The AI layer helps with the information problem.
Together, they turn an ordinary document store into something closer to a personal knowledge system — provided I don't forget the boring but essential parts: privacy, permissions, backups, model errors and source verification.
That's my idea of a useful AI Office.