Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IDP — Intelligent Document Processing

An MVP for algorithmic document search: upload documents, then search them with a hand-written TF-IDF + cosine similarity ranking engine. No external AI/LLM service is used anywhere in the backend — the ranking logic is plain Python, so there are no API keys to configure and nothing to run to get started besides the two servers below.

See docs/ARCHITECTURE.md for the full pipeline/scaling design and docs/DECISIONS.md for why this project avoids generative AI and how extraction is sequenced.

Features

  • Document upload.txt and .pdf (via pypdf), chunked paragraph-aware into ~600-word pieces for meaningful retrieval units.
  • Persistent storage — SQLite (backend/idp.db), survives restarts.
  • Algorithmic search — term frequency / inverse document frequency vectors built fresh per query from the full corpus, ranked by cosine similarity. Results are a ranked list of matching chunks with a score and highlighted matched terms — not a generated "answer."
  • Document management — list and delete uploaded documents.

Tech Stack

Backend:

  • Python 3 + FastAPI + Uvicorn
  • SQLite (stdlib sqlite3) for persistence
  • pypdf for PDF text extraction
  • numpy for vector math only — the TF-IDF/cosine-similarity algorithm itself is hand-written in backend/tfidf.py

Frontend:

  • Vite + React 18 + TypeScript
  • MUI (@mui/material) for components

Installation

Backend

cd backend
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

No .env file or API key is required.

Frontend

npm install

Optionally set VITE_API_URL (defaults to http://localhost:8001) via a .env.local file — see .env.example.

Usage

# Terminal 1
cd backend && python main.py        # http://localhost:8001

# Terminal 2
npm run dev                         # http://localhost:3000

API Endpoints

  • GET / — API info + document count
  • POST /api/upload — upload a .txt or .pdf file (multipart file field)
  • POST /api/search{"query": "...", "top_k": 5} → ranked chunk results
  • GET /api/documents — list uploaded documents
  • DELETE /api/documents/{id} — remove a document and its chunks
  • GET /docs — interactive API documentation

Example

curl -X POST http://localhost:8001/api/upload -F "file=@document.pdf"

curl -X POST http://localhost:8001/api/search \
     -H "Content-Type: application/json" \
     -d '{"query": "your search terms"}'

How It Works

  1. Upload — text is extracted (backend/extractors.py) and split into chunks (backend/chunking.py), then persisted to SQLite.
  2. Search — every chunk in the corpus is tokenized, a TF-IDF matrix is built fresh (backend/tfidf.py), the query is projected into the same vector space, and chunks are ranked by cosine similarity.
  3. Result — the top-k chunks are returned with filename, score, and the specific query terms that matched, for client-side highlighting.

Because TF-IDF's inverse-document-frequency term depends on the whole corpus, vectors are computed at query time rather than cached at upload time — this keeps rankings correct as new documents are added, at the cost of recomputing the matrix per search (fast at MVP scale).

Project Structure

Search-AI/
├── backend/
│   ├── main.py          # FastAPI app — routes only
│   ├── db.py            # SQLite persistence (documents, chunks)
│   ├── extractors.py    # .txt/.pdf -> text
│   ├── chunking.py      # paragraph-aware chunking
│   ├── tfidf.py         # hand-written TF-IDF + cosine similarity
│   └── requirements.txt
├── src/
│   ├── components/
│   │   ├── Header.tsx
│   │   ├── DocumentPanel.tsx   # upload, list, delete
│   │   └── AskPanel.tsx        # query box + ranked results
│   ├── api.ts            # typed fetch wrappers
│   ├── types.ts
│   ├── App.tsx
│   └── main.tsx
├── vite.config.ts
├── tsconfig.json
└── package.json

Deferred (known scope, not silently dropped)

  • OCR / scanned images, DOCX and formats beyond TXT/PDF
  • Smarter ranking (BM25, n-grams, phrase matching) as the next iteration on top of this TF-IDF baseline
  • Structured field/entity extraction, document classification
  • Auth, multi-tenancy, rate limiting
  • Production CORS lock-down (currently allow_origins=["*"] for local MVP)
  • Deployment/hosting

License

MIT

About

Search Tool using a React and Open AI Api integration including RAG

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages