Papyrus

Scientific RAG Assistant

Ask the Papers.

A multi-stage retrieval pipeline combining dense vector search, keyword matching, reciprocal rank fusion, and LLM reranking to surface the most relevant evidence from the indexed paper corpus.

Retrieval Pipeline

8-Stage Query Processing

Every query flows through this sequence. Click any step to explore — or watch the example query transform live as it moves through each stage.

User QueryInput

Natural language question submitted through the chat interface.

Scientific RAG Assistant

Query

What are unidirectional error correcting codes?

Q
Searching papers…
plain text → pipeline entry point
Query EmbeddingOpenAI
Pending
Dual RetrievalParallel
Pending
RRF FusionFusion
Pending
Threshold FilterFilter
Pending
LLM RerankerAI Score
Pending
Answer GenerationGenerate
Pending
Redis CacheCache
Pending

Click any step · auto-advances every 3 s

Retrieval Strategy

Dual Search + RRF Fusion

Two fundamentally different retrieval methods run in parallel then combined with Reciprocal Rank Fusion — each compensates for the other's blind spots.

Dense Vector Searchpgvector

The query vector is compared against all chunk embeddings using cosine similarity. Captures semantic meaning— finds conceptually related chunks even when exact keywords don't appear.

ORDER BY embedding <=> $query_vec LIMIT 20
Keyword SearchILIKE

Exact and partial term matching against raw chunk text. Reliable for proper nouns, acronyms, and technical terms that embeddings may not capture precisely.

WHERE text ILIKE '%query_term%' LIMIT 20

Reciprocal Rank Fusion

Each method returns its own ranked list. RRF assigns a score to every chunk based on its rank in each list, then merges them. A chunk that ranks highly in both lists scores highest. The constant k=60 smooths top-rank dominance.

RRF(d) = Σ
k + ranki(d)
k = 60

Technology

Production Stack

Each component was selected for performance, correctness, and minimal operational overhead on a single-node deployment.

FastAPI0.136

Async Python API with automatic OpenAPI docs, dependency injection, and CORS middleware.

PostgreSQL + pgvectorpg16 + 0.8

Primary store for chunk text and 1536-dim embeddings with an IVFFlat index for fast cosine similarity search.

Redis7-alpine

In-memory answer cache with a 1-hour TTL. Eliminates repeated LLM calls for identical queries.

OpenAIgpt-4o-mini

Dual role: text-embedding-3-small produces 1536-dim chunk embeddings; gpt-4o-mini handles LLM reranking and answer generation.

Evaluation

Retrieval Quality Metrics

The pipeline is evaluated against a curated set of query–paper pairs using standard information retrieval metrics.

Hit@K

1 if expected_paper ∈ top-K results, else 0

Fraction of queries where the expected paper appears in the top-K retrieved chunks. Measures whether the retriever surfaces the correct source at all.

MRR

1/N · Σ 1/rank(expected_paper)

Mean Reciprocal Rank rewards retrievers that surface the correct paper at a higher rank. A score of 1.0 means the expected paper is always ranked first.

Ready to explore the research?

Ask any question across 20 indexed papers. Grounded answers with full citations.

Open the Assistant