Skip to content

Latest commit

 

History

49 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF Chat (Rust + React)

Upload a PDF and chat with it. This repo contains a Rust backend API that ingests PDFs into an in-memory vector store (per session) and a React + Vite + Tailwind frontend that lets users upload a PDF, preview it, and ask questions against the uploaded content.

Primary use cases

  • Personal “chat with a PDF” for reports, specs, ebooks, and papers
  • Lightweight prototype for RAG-style PDF Q&A (session-scoped, single process)

Key features

  • PDF ingestion (text extraction → chunking → embeddings)
  • Semantic retrieval using cosine similarity + LLM answer generation (DeepSeek API)
  • Session isolation (session_id) so users don’t see each other’s documents
  • Dev-friendly CORS configuration for local frontends

Repository Layout

  • be/ — Rust (Axum) backend API
  • fe/ — React (Vite) frontend
  • screenshots/ — UI screenshots used in this README

Technical Requirements

Backend (Rust)

  • Rust: 1.85+ (required for edition = "2024")
  • Network access:
    • DeepSeek API calls (requires DEEPSEEK_API_KEY)
    • FastEmbed model download/cache on first run
  • Hardware (recommended): 8GB+ RAM (PDF extraction + embedding can be memory heavy)

Frontend (React)

  • Bun (recommended): 1.0+
    • Alternatively, Node.js: 18+ (if you prefer npm; project scripts are compatible)
  • Modern browser: Chrome / Firefox / Safari / Edge
  • Network access: PDF.js is loaded from a CDN at runtime

Installation

1) Clone the repo

macOS / Linux

git clone <YOUR_REPO_URL>
cd pdf-chat

Windows (PowerShell)

git clone <YOUR_REPO_URL>
cd pdf-chat

2) Backend setup (be/)

Copy the backend environment template and set your API key.

macOS / Linux

cp be/.env.sample be/.env

Windows (PowerShell)

Copy-Item be\.env.sample be\.env

Edit be/.env and set:

  • DEEPSEEK_API_KEY=...

Optional:

  • PORT=8080
  • BIND_ADDR=0.0.0.0:8080
  • CORS_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000
  • CORS_ALLOW_CREDENTIALS=false

Run the backend:

macOS / Linux

cd be
cargo run

Windows (PowerShell)

cd be
cargo run

Backend default URL: http://localhost:8080

3) Frontend setup (fe/)

Copy the frontend environment template and point it to your backend URL:

macOS / Linux

cp fe/.env.sample fe/.env

Windows (PowerShell)

Copy-Item fe\.env.sample fe\.env

Edit fe/.env:

VITE_BASE_URL_API=http://localhost:8080

Install dependencies and run:

Bun (recommended)

cd fe
bun install
bun run dev

Frontend default URL (Vite): http://localhost:5173

Usage

UI workflow

  1. Open the frontend in the browser.
  2. Click Upload PDF and select a PDF file (max size is enforced by the UI).
  3. After upload finishes, use the chat panel to ask questions about the PDF.

Screenshot

PDF Chat UI

Backend API (curl examples)

All user data isolation is session-based. Use the same session_id for upload and subsequent queries.

Ingest a PDF

curl -X POST "http://localhost:8080/ingest?session_id=my-session" \
  -F "file=@/path/to/document.pdf"

Ask a question

curl -X POST "http://localhost:8080/query?session_id=my-session" \
  -H "Content-Type: application/json" \
  -d '{"question":"Summarize the main points."}'

For full backend endpoint details, see:

  • be/README.md

Configuration

Backend environment variables

Located in be/.env:

  • DEEPSEEK_API_KEY (required): DeepSeek API key
  • PORT (optional): port number (default 8080)
  • BIND_ADDR (optional): bind address (default 0.0.0.0:{PORT})
  • CORS_ALLOWED_ORIGINS (optional): comma-separated list of allowed origins (or *)
  • CORS_ALLOW_CREDENTIALS (optional): true/false (only works with explicit origins, not *)

Frontend environment variables

Located in fe/.env:

  • VITE_BASE_URL_API (required): backend base URL (e.g. http://localhost:8080)

Contributing

Code standards

  • Rust: format with cargo fmt, lint with cargo clippy
  • Frontend: bun run lint, and format with bun run format
  • Don’t commit secrets (.env files should stay local)

Pull request process

  1. Create a branch: feat/<name> or fix/<name>
  2. Keep changes scoped and well-described
  3. Ensure builds pass:
    • cd be && cargo check
    • cd fe && bun run build
  4. Open a PR with:
    • What changed
    • Why it changed
    • How to test it

Issue reporting (template)

When filing a bug, include:

  • Steps to reproduce
  • Expected vs actual behavior
  • Screenshots / screen recordings (if UI-related)
  • Environment: OS, browser, Node/Bun version, Rust version
  • Relevant logs (browser console + backend logs)

Code of conduct

Be respectful, assume good intent, and keep feedback constructive. Harassment and discrimination are not tolerated.

License

No license file is included in this repository yet. Until a license is added, assume “all rights reserved” by the author(s).

If you want this to be open source, add a LICENSE file (e.g. MIT/Apache-2.0) and update this section accordingly.

Troubleshooting

CORS errors / requests blocked

  • Ensure the frontend origin (e.g. http://localhost:5173) is included in CORS_ALLOWED_ORIGINS in be/.env
  • Restart the backend after updating env vars

Backend fails to start: “Address already in use”

  • Another process is already using the port.
  • Stop the running process or change the port:
    • PORT=8081 cargo run

Frontend requests show as “canceled”

Common causes:

  • Backend CORS mismatch (see above)
  • Request timeout (PDF ingestion and LLM calls can take time)

“DEEPSEEK_API_KEY not found”

  • Set DEEPSEEK_API_KEY in be/.env and restart the backend.

First run is slow

  • FastEmbed may download a model on first use and cache it locally.

Maintainers / Contact

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages