Nexdoc is a high-performance offline document search system, its intelligent backend designed to process multiple document formats, extract and clean their content, generate semantic embeddings, store searchable document data in LanceDB, and provide fast, context-aware search.
The backend follows a modular layered architecture with a threaded processing pipeline, dynamic worker pool, file watching, semantic retrieval, hybrid filtering, ranking, and optional AI-powered responses.
Document Search & AI-Powered Results
This application demonstrates Nexdoc's complete offline document intelligence workflow, including multi-format document upload, real-time processing status, semantic search across indexed documents, and AI-powered contextual answers. It serves as a demonstration client for firms evaluating Nexdoc before deploying it as their offline document assistant.
Search & Retrieval
Every query runs through semantic vector search, hybrid filtering, and result ranking before returning results โ either as raw ranked matches in offline mode or as a synthesized AI answer with cited sources in AI mode.
Document Insights
Users can inspect file metadata, processing status, and topic extraction for each indexed document, giving full visibility into how Nexdoc understands and organizes their files.
- Features
- How It Works
- System Design
- Project Structure
- Tech Stack
- Document Processing Pipeline
- Search Pipeline
- Storage Architecture
- Layered Architecture
- Processing Characteristics
- Edge Cases & Reliability
- Privacy & Offline Architecture
- Setup
- API Modules
- Desktop Packaging
- Current Status
- Future Improvements
- Design Principles
- Author
- Images (OCR-based)
- PPTX
- TXT
- XLS / XLSX
- Multi-threaded document processing
- Dynamic worker pool based on available CPU cores
- Producer-consumer processing pipeline
- Real-time file detection using Watchdog
- Concurrent file processing
- Processing status tracking
- Text extraction
- Text cleaning and normalization
- Sentence-aware chunking
- Topic extraction
- File metadata extraction
- Semantic embeddings using Sentence Transformers
- Semantic vector search
- Hybrid filtering
- Result ranking
- Context-aware retrieval
- Offline search mode
- AI-powered search mode
- LanceDB vector database
- Vector embeddings stored with document metadata
- SQLite-based application data storage
- Persistent local storage
- Metadata-based document retrieval
- Local document processing
- Local embedding generation
- Local vector database
- No cloud backend required for core document processing and search
- Designed for privacy-focused desktop usage
- AI-powered query responses
- Relevant document sources returned with AI answers
- Gemini API integration for AI-assisted responses
- Offline mode remains available without AI services
User Upload
โ
File Storage
โ
File Watching
โ
Queue
โ
Dynamic Worker Pool
โ
File Processing
โ
Text + Metadata Extraction
โ
Text Cleaning
โ
Chunking
โ
Embedding Generation
โ
LanceDB Storage
โ
Search
โ
Hybrid Filtering
โ
Ranking
โ
Offline / AI Response
Nexdoc uses a producer-consumer architecture for document processing. Uploaded files are placed into a processing queue and consumed by dynamically created workers. The worker pool determines its capacity from the available CPU resources, allowing the backend to adapt to different machines.
Each worker independently processes a document through extraction, cleaning, chunking, embedding generation, and LanceDB persistence โ while the main application remains responsive.
โโโโโโโโโโโโโโโโโโโโ
โ User Uploads โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ File Storage โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ File Watcher โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ Processing Queue โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโ โโโโโโโโโโโโ
โ Worker 1 โ โ Worker N โ
โโโโโโฌโโโโโโ โโโโโโฌโโโโโโ
โ โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ File Processing โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ Text + Metadata โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ Text Cleaning โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ Chunking โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ Embedding โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโ
โ LanceDB โ
โโโโโโโโโโโโโโโโโโโโ
Nexdoc_Backend/
โ
โโโ app/
โ โโโ services/
โ โ โโโ uploadPPTX/
โ โ โ โโโ upload_pptx_service.py
โ โ โ โโโ __init__.py
โ โ โโโ uploadTXT/
โ โ โ โโโ upload_txt_service.py
โ โ โ โโโ __init__.py
โ โ โโโ uploadXLS/
โ โ โโโ upload_xls_service.py
โ โ โโโ __init__.py
โ โ
โ โโโ utils/
โ โ โโโ file_metadata_formatter.py
โ โ โโโ text_cleaner.py
โ โ โโโ topic_extractor.py
โ โ โโโ __init__.py
โ โ
โ โโโ main.py
โ โโโ NexDocBackend.spec
โ โโโ __init__.py
โ
โโโ database/
โ โโโ nexdoc.db
โ
โโโ README.md
โโโ requirements.txt
โโโ NexDocBackend.spec
โโโ runtime_hook.py
Note: Runtime-generated directories and large local assets โ such as the virtual environment, model files, vector database data, build output, distribution output, OCR runtime files, and uploaded documents โ are intentionally omitted from the documented source tree.
| Category | Technologies |
|---|---|
| Backend | Python, FastAPI, Uvicorn, Pydantic |
| Document Processing | PyMuPDF, pytesseract, python-pptx, pandas, openpyxl |
| AI / Machine Learning | Sentence Transformers (all-MiniLM-L12-v2), PyTorch |
| Vector Search | LanceDB |
| Local Storage | SQLite, Local filesystem |
| Processing & Concurrency | Watchdog, Threaded producer-consumer pipeline, Dynamic worker pool |
| AI Mode | Gemini API |
| Packaging | PyInstaller |
The user uploads a supported document through the FastAPI upload endpoints. The upload service:
- Validates the file
- Stores the file locally
- Prevents invalid uploads
- Makes the file available for processing
A Watchdog-based file watcher monitors the configured document storage location. When a new file is detected, it is added to the processing workflow so that files can also be processed automatically when they appear in the watched directory.
Detected files are placed into a processing queue. The queue separates file production from file processing, allowing uploaded files to wait safely until a worker becomes available.
Nexdoc creates a worker pool dynamically according to the available CPU resources of the machine. This allows the same backend to adapt its processing concurrency across different desktop systems instead of relying on a fixed number of workers.
Available CPU Resources
โ
Worker Capacity Calculation
โ
Dynamic Worker Creation
โ
Concurrent File Processing
Each worker takes a file from the queue and sends it to the appropriate file processor based on its format:
| Format | Processor |
|---|---|
| PDF Processor | |
| Image | Image Processor / OCR |
| PPTX | PPTX Processor |
| TXT | TXT Processor |
| XLS | XLS Processor |
The processor extracts the document's usable content and associated metadata.
Extracted text is cleaned and normalized before being passed to the chunking stage. This removes unnecessary formatting/noise and produces more consistent text for downstream processing.
Large extracted documents are divided into smaller, meaningful text chunks. Chunking makes the content suitable for embedding and improves the granularity of semantic retrieval. Document metadata is preserved alongside the corresponding chunks.
Each chunk is converted into a numerical vector representation using the local Sentence Transformer model.
Text Chunk
โ
Sentence Transformer
โ
Embedding Vector
The embedding captures the semantic meaning of the text and allows similar concepts to be retrieved even when the exact keywords differ.
The generated embeddings are stored in LanceDB together with the corresponding document information and metadata.
Embedding Vector
+
Document Content
+
Document Metadata
โ
LanceDB
This allows the system to perform vector similarity search while retaining the information required to present the original document context to the user.
When a user submits a search query, Nexdoc follows a multi-stage retrieval process.
User Query
โ
Query Processing
โ
Candidate Retrieval
โ
Hybrid Filtering
โ
Result Ranking
โ
Offline / AI Mode
โ
Final Response
The user's query is processed and converted into a representation suitable for document retrieval.
Relevant document chunks are retrieved from the locally stored vector data using semantic similarity.
Retrieved candidates are passed through the hybrid filtering stage to improve the relevance of the candidate set.
The filtered candidates are ranked according to their relevance to the user's query, producing an ordered set of results for the final response stage.
In offline mode, the ranked document results are processed locally to produce a readable response. No external AI service is required for this mode.
In AI mode, the ranked document context is passed to the AI service to generate an answer. The response contains:
- AI-generated answer
- Relevant document sources
- Source metadata
Nexdoc uses different storage mechanisms for different responsibilities.
Used for:
- Document embeddings
- Vector similarity retrieval
- Searchable document content
- Associated metadata
Used for application-level structured data such as:
- Processing status
- Statistics
- Recent searches
- Other lightweight application state
Used for:
- Uploaded documents
- Application assets
- Local runtime data
Nexdoc follows a layered backend architecture that separates API handling, business logic, data access, and domain functionality.
Client
โ
Controllers
โ
Services
โ
Features / Processing Logic
โ
Repositories
โ
LanceDB / SQLite / Filesystem
| Layer | Responsibility |
|---|---|
| Controllers | Handle HTTP requests and responses |
| Services | Contain application-level business logic and coordinate different components |
| Features | Contain core domain functionality โ Search, Chunking, Embedding, File processing, Worker management |
| Repositories | Abstract persistence operations from the rest of the application |
| Schemas | Define request and response structures using Pydantic models |
| Stage | Purpose |
|---|---|
| Upload | Store and validate incoming files |
| File Watching | Detect newly available files |
| Queue | Decouple file arrival from processing |
| Worker Pool | Process multiple files concurrently |
| File Processing | Extract document content |
| Cleaning | Normalize extracted text |
| Chunking | Divide content into searchable units |
| Embedding | Convert chunks into vectors |
| LanceDB | Persist vectors and document information |
| Search | Retrieve relevant document chunks |
| Ranking | Order results by relevance |
| Response | Return offline or AI-assisted results |
Nexdoc is designed to handle common document-processing failures, including:
- Corrupted documents
- Unsupported file formats
- Empty document content
- OCR failures
- Failed document processing
- Partial processing failures
- Processing status tracking
- Multiple files arriving concurrently
The core document-processing pipeline runs locally on the user's machine.
Documents
โ
Local Filesystem
โ
Local Processing
โ
Local Embeddings
โ
Local LanceDB
โ
Local Search
This allows sensitive documents to remain on the user's machine during normal offline processing and search operations.
AI mode is an optional internet-dependent capability because it uses the configured Gemini API.
git clone <your-repo>
cd Nexdocpython -m venv venvWindows
venv\Scripts\activatepip install -r requirements.txtuvicorn app.main:app --reloadThe backend will be available at:
http://127.0.0.1:8000
Nexdoc exposes REST APIs for major application operations.
| Module | Endpoints / Capabilities |
|---|---|
| Upload | PDF upload, Image upload, PPTX upload, TXT upload, XLS/XLSX upload |
| Search | Document search, Offline search mode, AI search mode |
| Status | File processing status, Statistics, Document and processing statistics |
| Recent Searches | Recent search history |
| Download | Processed document/file retrieval |
Nexdoc is designed to operate as an offline desktop application.
The Python backend can be packaged using PyInstaller, allowing the backend runtime and required Python dependencies to be distributed with the desktop application.
Nexdoc Desktop Application
โ
Electron Frontend
โ
Local FastAPI Backend
โ
Local Processing Pipeline
โ
Local Storage
This eliminates the requirement for a separately deployed backend server for the core application.
- โ Multi-format document processing
- โ PDF processing
- โ Image OCR processing
- โ PPTX processing
- โ TXT processing
- โ XLS / XLSX processing
- โ File watching
- โ Queue-based processing
- โ Dynamic worker pool
- โ Multi-threaded processing
- โ Text cleaning
- โ Chunking
- โ Local embedding generation
- โ LanceDB vector storage
- โ Semantic search
- โ Hybrid filtering
- โ Result ranking
- โ Offline search mode
- โ AI search mode
- โ Processing status tracking
- โ SQLite application storage
- โ FastAPI REST API
- โ PyInstaller packaging support
- โ Electron desktop integration
Potential areas for further optimization include:
- ONNX-based embedding inference
- Faster embedding model startup
- Advanced ranking strategies
- Improved hybrid retrieval
- Search result caching
- More advanced chunking strategies
- Additional document formats
- Further worker-pool optimization
- Improved application observability
- Advanced AI response optimization
- Offline-first
- Modular architecture
- Layered architecture
- Separation of concerns
- Concurrent processing
- Resource-aware worker management
- Fault tolerance
- Local-first data storage
- Scalable processing pipeline
- Privacy-focused document processing
Ravi Sharma Full Stack Developer / AI Engineer




