How kaijiezhu11/searchanything works
Project type and purpose
• This is a monolithic, full-stack Python application (“SearchAnything”) that provides a local semantic search engine for both text and images. It offers two frontends:
• A command-line interface (anything.py) for inserting, searching, and deleting files.
• A Streamlit web interface (app.py) for friendly, browser-based search.
• It supports ingesting files (pdf, txt, md, jpg, jpeg, png), parsing them into text or raw image data, embedding them via AI models, storing embeddings in a local database, and retrieving nearest neighbors by cosine similarity.
File structure
• Top-level scripts:
• anything.py – CLI entry point
• app.py – Streamlit UI entry point
• index.py – likely core orchestration of insert/search
• database.py – database schema and access (SQLite3)
• config.py – model paths, DB paths, hyperparameters
• monitor.py – file-system watcher (planned/partial)
• asr.py – placeholder for audio support (future)
• utils.py – shared helpers (logging, file I/O)
• test.py – simple smoke tests
• process/ (parsing pipeline):
• parser_base.py – abstract parser interface
• pdfparser.py, mdparser.py, txtparser.py – text extraction
• imgparser.py – image loading/preprocessing
• docparser.py – orchestrator calling the specific parser
• tools/search4files.py – helper to locate files on disk
• env.yaml – Conda environment spec
README for insights
• Two-step architecture:
a. Embedding: transforms each document or image into a fixed-size vector using sentence-transformers (all-mpnet-base-v2 for text, clip-ViT-B-32 for images).
b. Save & Retrieve: store embeddings + metadata in SQLite; at search time embed the query, compute cosine similarity against stored embeddings, and return top matches.
• Emphasizes running fully locally for privacy.
1. User Interfaces
– CLI (anything.py)
– Web UI (app.py / Streamlit)
2. Core Service / Orchestrator (index.py, monitor.py)
3. Parser Pipeline (process/)
4. Embedding Service (sentence-transformers models)
5. Database (SQLite3)
6. File System (raw documents & images)
7. External Dependencies (NLTK, sentence-transformers, Streamlit)
• UI → Core Service: user issues “insert”/“search” commands
• Core Service → Parser Pipeline: load file(s) from File System
• Parser Pipeline → Embedding Service: extracted text/image → model → embedding vector
• Embedding Service → Database: insert (filepath, metadata, vector)
• On search: Core Service → Embedding Service: embed query → vector
• Core Service → Database: fetch all embeddings → compute cosine similarity → filter & sort
• Core Service → UI: return ranked results
• Monitor → Core Service: file‐system events trigger auto‐insert/delete (future)
c. Architectural patterns & design principles:
– Pipeline pattern (parse → embed → store/retrieve)
– Separation of concerns (UI, orchestration, parsing, embedding, persistence)
– Modular plugin style for parsers (parser_base + concrete parsers)
d. Key technologies & libraries:
– Python 3.x, Conda env
– sentence-transformers (all-mpnet-base-v2, clip-ViT-B-32)
– SQLite3 (database.py)
– Streamlit (app.py)
– NLTK (punkt tokenizer)
– Watchdog or custom logic (monitor.py)
Detail
• Parser_base → individual parsers relationship (inheritance/plugin).
• That index.py calls database.py and utils.py.
• Config.py feeding settings into Core Service and Embedding Service.