← Back to Projects
FileQuery

FileQuery

Ask questions about your own documents and get answers drawn only from them, with the sources shown.

Next.jsTypeScriptTailwind CSSFastAPIPython 3.14SQLAlchemy 2.0PostgreSQLpgvectorLangChainAWS S3AWS SQSAWS LambdaAmazon Titan Embeddings V2Cohere Rerank 3.5Amazon Nova MicroGoogle Cloud Run
320+
automated backend tests
4
retrieval stages: vector, keyword, fuse, rerank
14
question evaluation set for the retrieval pipeline
13
database migrations

The problem

General chatbots answer confidently from their training data, or make something up, and they cannot read private files at all. FileQuery lets people upload their own documents into project folders, finds the passages most likely to answer a question, and tells the model to answer only from those passages. I built it to work through a real cloud RAG pipeline end to end, rather than just calling an AI API.

What it does

Project Knowledge Bases

Groups documents into separate project workspaces, so a question only searches the files that belong to it.

Multi-Format Ingestion

Extracts text from PDF, DOC, DOCX, CSV, Markdown and TXT files as they are uploaded.

Hybrid Search With Reranking

Combines meaning-based and keyword search, then reranks the best candidates, so both paraphrases and exact terms are found.

Follow-Up Questions

Turns a follow-up such as 'what about the second option' into a standalone search before retrieval.

Answers From Your Files

The model is instructed to answer only from the retrieved passages, and answers show the sources they were drawn from.

Background Processing

Uploaded files are processed through a queue and a worker, so the app stays responsive while a document is indexed.

See it working

A project's files tab listing four uploaded Markdown files above an upload area.
Files are grouped into projects, and each project searches only its own files.
A chat where an answer is followed by chips for each source passage it used.
Answers list the passages they were based on.
A dialog showing the source file name and the exact cited text.
Open a source to see the file and the exact passage.

How it's built

How FileQuery fits together: files go from the browser straight to S3, a queue and Lambda worker embed them into PostgreSQL, and questions are answered through search, reranking and Bedrock models.

Frontend

  • Next.js with TypeScript and Tailwind CSS.
  • Server Actions call the API with the sign-in token held in an HTTP-only cookie.

API and database

  • FastAPI with 17 documented endpoints, SQLAlchemy 2.0 and 13 Alembic migrations.
  • PostgreSQL with pgvector for meaning-based search and built-in full-text search for keywords.
  • Rate limits keyed per user on Redis, monthly message caps, and a read-only public demo mode.

Ingestion pipeline

  • The browser uploads straight to S3, then the API confirms the upload and puts a job on an SQS queue.
  • A Lambda worker extracts text, splits it into chunks with LangChain and creates embeddings with Amazon Titan Text Embeddings V2.

Answering a question

  • The question is rewritten into a standalone search, then run against pgvector and full-text search.
  • The two result lists are merged with reciprocal rank fusion, reranked by Cohere Rerank 3.5, and the top five passages go to Amazon Nova Micro to write the answer.
  • The services run on Google Cloud Run and the worker image is built and pushed to AWS from GitHub Actions.

Key decisions and tradeoffs

  • Combine keyword and meaning-based search, then rerank

    Searching by meaning misses exact terms such as part numbers, and keyword search misses paraphrases. Running both, merging the results and reranking the best candidates finds the right passage more often than either alone.

    The cost: Every question makes an extra model call for reranking, which adds latency and cost, and there are more settings to tune.

    Technical detail

    pgvector cosine search with a 0.14 similarity threshold returns 20 candidates, Postgres full-text search (with a GIN index) returns its own list, reciprocal rank fusion merges them with k=60, and Cohere Rerank 3.5 on Bedrock keeps the top 5.

  • Process uploads with managed queues and workers

    Extracting and embedding a long document takes a while. A managed queue and a worker keep that out of the web request, and I never have to run or patch the queue myself.

    The cost: Cost can grow faster than a self-run queue at high volume, which I accepted because this is a portfolio project, not a production system at scale.

    Technical detail

    SQS triggers a Lambda container image. The image is built in stages and compiles antiword from source so old .doc files can be read.

  • Lock down uploads before they reach the server

    Files go straight from the browser to S3, so the server never handles the file itself, but the upload link has to limit what can be sent.

    The cost: The client must declare the file type and size up front, and the extra confirm step adds one more request.

    Technical detail

    The presigned upload is pinned to the declared content type and an exact size range, the API checks the stored object with head_object before queuing it, and per-user storage quotas apply.

  • Stay inside AWS for models

    I already used S3 and SQS, so Titan embeddings and Nova Micro kept the services, billing and sign-in in one place and kept running costs down.

    The cost: Less choice of model than a provider-agnostic setup, and the app is split across two clouds, with the frontend and API on Google Cloud Run and storage and models on AWS.

  • Test the pipeline without the cloud

    Deterministic fakes for Bedrock, S3 and SQS let the whole upload, chunk, embed and retrieve flow run in ordinary tests, quickly and for free.

    The cost: The fakes prove the pipeline is wired correctly, but they do not measure how good a real model's answers are.

    Technical detail

    A 14-case evaluation set (10 answerable and 4 unanswerable questions) runs through the real upload, extract, chunk and embed code and checks the expected source, evidence and refusal. Known bugs are recorded as strict expected failures so they cannot be forgotten.

Hard problems I solved

  • Making retrieval good enough to trust

    The problem
    Plain vector search sometimes missed specific terms or returned weak matches.
    What I did
    I added query rewriting for follow-up questions, hybrid keyword and vector search, and a reranking step. I checked each change by running a set of test questions and looking at which chunks came back and their similarity scores, then turned that set into the evaluation tests.
    The result
    Questions about specific terms now find the right passage, and the evaluation set guards against regressions.
  • Choosing chunk sizes

    The problem
    Chunks that are too small lose surrounding context, and chunks that are too large dilute the match.
    What I did
    I tested different sizes and overlaps with LangChain's recursive splitter and settled on 1,500 characters with a 200-character overlap.
    The result
    A reasonable default for mixed documents. A header-aware Markdown splitter is written and tested but not yet switched on.

Testing and quality

About 325 backend tests across 26 files, about 190 frontend tests and 13 Playwright browser tests.

GitHub Actions runs backend tests against a real pgvector database, ruff, pip-audit, ESLint, type checks, Vitest, npm audit, a build and the Playwright tests. A second workflow pushes the worker image to AWS.

  • 13 Alembic migrations, including a full-text index and foreign key indexes.
  • Passwords hashed with bcrypt, with matching timing for unknown accounts.
  • Analytics use salted IDs and never record document content.

Known limitations

  • Vector search is an exact scan with no approximate-nearest-neighbour index yet. That is fine at this size but would not scale.
  • Answers currently cite every reranked passage, including some that were not used. A test marks this known gap.
  • The evaluation runs on fakes, so I have no measured accuracy for a real model yet.

Database model

Schema for FileQuery

Use and further reading

I use it myself to search dense developer documentation. In my testing it answered from the uploaded files and declined to answer when the files did not contain the information, though I have not measured accuracy against a real model.

Read more in the repo: Public demo mode designCI workflow