How raahulsaxena/rag-based-patent-analysis-tool works
1. What this repo is centered on
This repository is a patent retrieval / analysis pipeline built around a RAG-style workflow, but the checked-in tree is mostly the retrieval side: patent text corpus, precomputed search artifacts, and evaluation utilities.
2. Raw document corpus
The documents/ directory is the source content layer. It contains patent-like text files such as karafin.txt, lucente.txt, williams.txt, plus matching *_meta.txt files that likely hold metadata or labels for each document. office_action.txt appears to be a separate document type in the same corpus.
3. Derived retrieval artifacts
chunks_array.npz and queries_array.npz are offline-generated NumPy archives that look like the main indexing inputs for retrieval. These are the boundary between preprocessing and runtime: the system likely avoids re-reading and re-chunking raw text on every query.
4. Query definitions and test fixtures
queries.json provides example or benchmark queries, while sample_input.py likely demonstrates the expected runtime input format. These are the external interface for the retrieval pipeline and the evaluation harness.
5. Main runtime entry point
retriever.py is the primary application module named in the repo. Based on the tree and README, it is the component that takes a query, loads the precomputed arrays, ranks document chunks, and returns the most relevant patent content.
6. Similarity and ranking support
jaccard.py is a dedicated similarity module. It likely provides lexical overlap scoring used either as the retrieval metric itself or as a post-retrieval comparison step for patent-to-patent matching.
7. Evaluation / validation path
retriever-test.py is the test harness for the retrieval pipeline. It probably exercises retriever.py against queries.json and the stored NumPy artifacts to verify ranking quality or regression behavior.
8. End-to-end data flow
The likely flow is: raw patent documents → chunking / preprocessing → saved NumPy arrays → query input → retrieval scoring → ranked chunk/document results. The comparison path likely branches through jaccard.py for pairwise similarity between documents or chunks.
9. Architecture boundaries
There is a clear separation between:
- source data: documents/
- derived index/cache data: *.npz
- query/test data: queries.json, sample_input.py
- runtime logic: retriever.py, jaccard.py
- validation: retriever-test.py
10. RAG-related note
The README describes summarization, comparison, and classification features, but those implementation files are not present in this tree. So, for an architecture diagram of this snapshot, the safest interpretation is that the repo currently exposes a retrieval-focused core that would feed a downstream generator or analysis layer, rather than a complete end-to-end RAG app in the checked-in files.
11. Technology footprint
The code is Python-based and the stored arrays imply heavy use of NumPy for persistence and fast loading. The README mentions transformers, torch, and scikit-learn, but those are not visible in the file tree; they may support a richer version of the pipeline, though the present repository layout is lightweight and offline-index driven.
12. What to draw in an architecture diagram
A good diagram would show a document corpus service/input, an offline preprocessing/indexing stage, a query-time retriever, a similarity/scoring utility, and a test/evaluation lane. The key architectural concept is that most expensive work appears to be done ahead of time and stored in .npz artifacts, leaving the runtime path focused on fast lookup and ranking.
Main entry points: retriever.py Retriever · chunks_array.npz Chunks index · documents Documents · retriever-test.py Retriever test
Components 12
Source corpus
Raw patent and related text inputs.
- Documents · Raw patent text and metadata files.
documents - Karafin · Representative patent document.
documents/karafin.txt - Lucente · Representative patent document.
documents/lucente.txt - Williams · Representative patent document.
documents/williams.txt - Office action · Additional document type in the corpus.
documents/office_action.txt
Derived index
Offline-generated retrieval artifacts.
- Chunks index · Precomputed chunk representations for retrieval.
chunks_array.npz - Queries index · Precomputed query-related representations.
queries_array.npz
Runtime and evaluation
Query-time retrieval, scoring, and validation.
- Queries · Example or evaluation queries.
queries.json - Sample input · Expected runtime input format.
sample_input.py - Retriever · Loads cached arrays and ranks relevant chunks.
retriever.py - Jaccard · Lexical overlap scoring for comparison or ranking.
jaccard.py - Retriever test · Regression and quality checks for retrieval behavior.
retriever-test.py
Connections 16
- Documents → Karafin: contains · Corpus includes patent text files.
- Documents → Lucente: contains · Corpus includes patent text files.
- Documents → Williams: contains · Corpus includes patent text files.
- Documents → Office action: contains · Corpus includes additional legal text.
- Karafin → Chunks index: chunked into · Raw text is transformed into retrieval chunks.
- Lucente → Chunks index: chunked into · Raw text is transformed into retrieval chunks.
- Williams → Chunks index: chunked into · Raw text is transformed into retrieval chunks.
- Office action → Chunks index: chunked into · Raw text is transformed into retrieval chunks.
- Chunks index → Retriever: loads · Retriever reads cached chunk representations.
- Queries index → Retriever: loads · Retriever may use cached query representations.
- Queries → Retriever: drives · Benchmark queries are passed into retrieval.
- Sample input → Retriever: formats input · Example input structure for runtime use.
- Retriever → Jaccard: scores with · Retriever can use lexical similarity for ranking.
- Jaccard → Retriever test: verified by · Similarity behavior is exercised through tests.
- Retriever → Retriever test: tested by · Retrieval output is validated by the test harness.
- Queries → Retriever test: fixtures · Tests likely use benchmark queries as input.