PatentIQ is an enterprise-grade, full-stack AI platform for automated patent prior-art retrieval, semantic claim analysis, metadata filtering, and RAG-driven novelty scoring.
- Overview
- How the Project Works & System Flow
- Key Features
- Architecture & Tech Stack
- Technical Interview Guide & Core Concepts
- Project Structure
- Documentation Index
- Getting Started
- CLI Scripts & Dataset Tools
- API Documentation & Endpoints
- Benchmarking & Evaluation
- Testing
- License
Patent prior-art searching traditionally requires laborious manual Boolean queries across massive patent databases. PatentIQ modernizes patent analysis by combining dense vector embeddings with metadata-filtered similarity retrieval and Retrieval-Augmented Generation (RAG).
It evaluates patent claims against prior art using local LLMs (qwen2.5:3b / llama3), calculates a heuristic Confidence Score across multiple dimensions (retrieval precision, vector similarity distance, section matching, and LLM certainty), and presents actionable technical insights through an interactive 3D command center interface.
Prior-art patent search has historically been a manual, costly bottleneck in intellectual property law. Patent attorneys typically spend 15 to 30 hours per invention constructing complex Boolean query matrices across fragmented databases. Because patent drafters deliberately use obscure technical synonyms to broaden claim scope (e.g., describing a pencil as an "elongated cylindrical writing instrument having an internal frangible marking core"), traditional keyword queries often miss critical prior art, exposing inventors to multi-million-dollar patent infringement lawsuits or novelty rejections under 35 U.S.C. Β§ 102.
sequenceDiagram
autonumber
actor User as Inventor / IP Attorney
participant UI as React 19 Client
participant Server as Fastify API (Clean Arch)
participant Ollama as Local Ollama (nomic-embed + Qwen)
participant Pinecone as Pinecone Vector DB
participant BM25 as Sparse BM25 Lexical Service
participant RRF as Reciprocal Rank Fusion (RRF)
participant Conf as Heuristic Confidence Engine
participant Postgres as PostgreSQL (Prisma ORM)
User->>UI: Submits invention disclosure & metadata filters
UI->>Server: POST /api/rag/analyze { query, topK, filters }
Server->>Server: Validate payload via Zod DTO schema
par Multi-Stage Hybrid Retrieval
Server->>Ollama: Generate 768-dim vector (nomic-embed-text)
Ollama-->>Server: Dense float vector (~42ms)
Server->>Pinecone: Query vector cosine similarity + metadata filters
Pinecone-->>Server: Dense candidate patents
and
Server->>BM25: Query sparse keyword corpus
BM25-->>Server: Sparse lexical candidates
end
Server->>RRF: Fuse dense & sparse ranks (k=60, w_dense=0.6, w_bm25=0.4)
RRF-->>Server: Top-K deduplicated & fused prior-art candidates
par Concurrent RAG AI Analysis
Server->>Ollama: Novelty Analysis Prompt (Qwen 2.5 3B)
Ollama-->>Server: 7-section structured novelty report JSON
and
Server->>Ollama: Section & Claim Overlap Prompt (Qwen 2.5 3B)
Ollama-->>Server: Itemized claim overlap matrix JSON (Claims 1..N)
end
Server->>Conf: Compute Multi-Factor Confidence Score (Retrieval + Analysis)
Conf-->>Server: Final Score (0β100) + Qualitative Badge (High/Moderate/Low)
Server->>Postgres: Persist search query, candidate patents & RAG report
Server-->>UI: Return combined prior-art matches, report & confidence telemetry
UI-->>User: Render interactive 3D constellation cluster & analysis dashboard
-
Multi-Stage Hybrid Search: Pairs 768-dimensional dense vector embeddings (
nomic-embed-text) with sparse lexical tokens (BM25), fused via Reciprocal Rank Fusion (RRF) ($k=60$ , vector weight$0.6$ , BM25 weight$0.4$ ) to combine conceptual understanding with exact patent-number/keyword precision. -
Concurrent Dual-Engine RAG: Single-pass retrieval triggers two parallel LLM executions via
Promise.allusing local Qwen 2.5 3B (NoveltyAnalysisServicefor patentability syntheses andOverlapAnalysisServicefor claim-by-claim overlap matrices) with strict anti-hallucination prompt constraints. - Multi-Factor Heuristic Confidence Scoring: Mathematically evaluates retrieval precision, score decay distribution, metadata completeness, count penalties, and claim overlap density into a calibrated 0β100 score.
- Interactive 3D Constellation Visualizer: Renders prior-art relationships in an interactive Three.js 3D space where Euclidean distance reflects semantic similarity.
- Polyglot Persistence: Separates vector storage and similarity indexing (Pinecone) from transactional search history, session persistence, and audit logging (PostgreSQL via Prisma ORM).
- π Semantic Prior-Art Search: Dense vector search powered by Pinecone and Ollama embeddings (
nomic-embed-text). - π― Granular Metadata Filtering: Filter prior-art queries by IPC classification codes, country/jurisdiction, publication date range, assignee/owner, and document sections (claims, abstract, description).
- π§ RAG Novelty & Prior-Art Analysis: Automated AI evaluation of technical novelty, non-obviousness risks, overlapping claim elements, and technical differentiators using
qwen2.5:3b. - π Heuristic Confidence Scoring Engine: Multi-metric scoring system evaluating retrieval precision/recall, vector distance, and LLM certainty mapped to qualitative confidence indicators.
- πΎ Search History & Persistence Layer: Atomic transaction storage via Prisma ORM and PostgreSQL to log user search sessions, retrieved patent metadata, and novelty reports.
- β‘ Dataset Pipelines & Benchmarking: Built-in CLI tooling for dataset cleaning, section extraction, vector embedding generation, Pinecone batch ingestion, and retrieval benchmarking (Precision@K, Recall@K, MRR, NDCG, Latency P95/P99).
- π¨ Modern Interactive UI: High-density command center built with React 19, Vite, Tailwind CSS v4, Framer Motion, and Three.js 3D visualizer in a cohesive Slate/Indigo theme.
PatentIQ follows Clean Architecture with strict Dependency Injection (DI) and modular separation of transport, domain, and infrastructure layers.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React 19 Client β
β (Vite + TailwindCSS + Framer Motion + 3D) β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββ
β REST API (/api/v1/*)
ββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββ
β Fastify Server β
β (Dependency Injection Container + Zod Validation) β
ββββββββββ¬ββββββββββββββββββββ¬ββββββββββββββββββββ¬βββββββββ
β β β
ββββββββββΌβββββββββ ββββββββββΌβββββββββ ββββββββββΌβββββββββ
β Pinecone DB β β PostgreSQL DB β β Ollama LLM β
β (Vector Search) β β (Prisma ORM) β β (Embed & RAG) β
βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββ
- Runtime: Node.js & TypeScript
- Web Framework: Fastify v5 (with CORS, Helmet, Rate Limit, Swagger OpenAPI, Multipart)
- Database & ORM: PostgreSQL & Prisma ORM v7
- Vector Database: Pinecone Database SDK (
dimension: 768,metric: cosine) - LLM & Embeddings: Ollama (
nomic-embed-text,qwen2.5:3b/llama3) - Validation: Zod schema validation & DTO typing
- Testing: Vitest & Supertest
- Framework: React 19 & TypeScript
- Build Tool: Vite v8
- Styling: Tailwind CSS v4
- Animations & 3D: Framer Motion & Three.js / React Three Fiber
- Icons & UI: Lucide React
π‘ Master Guide Available: For the complete 720-line deep dive with 26 technical questions, mathematical proofs, STAR behavioral scenarios, and code references, explore the dedicated PROJECT_EXPLANATION_AND_INTERVIEW_GUIDE.md.
"PatentIQ is an enterprise AI platform for automated prior-art patent search and novelty scoring. Traditional patent search takes 15 to 30 hours of manual Boolean queries across fragmented databases and often fails when different terminology is used. PatentIQ solves this by combining hybrid semantic searchβpairing dense Pinecone vector embeddings with sparse BM25 lexical search via Reciprocal Rank Fusionβwith a local, privacy-preserving RAG pipeline powered by Ollama and Qwen 2.5 3B. It automatically maps claim overlaps, computes a multi-factor mathematical Confidence Score, and visualizes patent clusters in an interactive Three.js 3D space, cutting patentability analysis time from hours to seconds."
1. Why did you choose Fastify over Express or NestJS?
- Throughput & Efficiency: Fastify is up to 2x faster than Express due to its compiled JSON serialization (
fast-json-stringify) and radix-tree routing (find-my-way), minimizing server overhead during high-throughput AI orchestration. - Encapsulated Plugin Architecture: Fastify's lifecycle hooks provide clean dependency scoping, making it straightforward to build our custom Dependency Injection container (
di.plugin.ts) without the heavyweight boilerplate of NestJS. - Built-in Schema Validation: Native integration with Zod schemas enables strict DTO validation and auto-generated Swagger documentation.
2. Why use local Ollama models instead of the OpenAI / Anthropic cloud API?
- Trade Secret Protection & Pre-Grant Privacy: Unfiled patent ideas are proprietary trade secrets. Sending unpublished invention claims to public cloud AI APIs risks breaching non-disclosure agreements and forfeiting patent rights through public disclosure.
- Zero Cloud Inference Costs: Patent analysis involves processing dense technical documentation across multiple candidates. Local execution on
nomic-embed-textandqwen2.5:3beliminates per-token API costs. - Deterministic Offline Availability: Protects the platform from external cloud rate limits, network outages, and pricing tier changes.
3. Why Hybrid Search (Dense + BM25) instead of pure vector search?
-
The Exact Keyword Vocabulary Problem: Pure dense embeddings excel at fuzzy semantic concepts (e.g. connecting "drone" with "unmanned aerial vehicle"), but frequently fail on exact patent numbers (e.g.
US10948372B2), chemical formulas, or specific trademarked part names. -
Reciprocal Rank Fusion (RRF): Running BM25 alongside Pinecone dense vectors and fusing them via RRF (
$k=60$ , vector weight$0.6$ , BM25 weight$0.4$ ) ensures that candidates scoring high across both systems rise to the top without needing to normalize disparate score scales.
4. How do you prevent LLM hallucinations when evaluating technical patent claims?
- Strict Context Grounding: Prompts explicitly designate the LLM as an objective patent examiner and instruct it to reason only from the provided patent metadata.
- Prohibition of Fabricated Identifiers: The model is strictly forbidden from inventing patent numbers, filing dates, or non-existent claim numbers.
- Explicit Extraction Constraints: For claim overlap analysis, the prompt forces the model to cite specific claim numbers (e.g., "Claim 3") and quote the exact technical rationale.
- Fallback Sanitization: Regex parsers sanitize markdown fences (
json ...) and validate payload schemas with deterministic fallbacks if the model returns malformed JSON.
5. How is the multi-factor Confidence Score mathematically calculated?
Instead of relying solely on raw vector similarity, PatentIQ computes a holistic 0β100 score:
-
Retrieval Confidence (
$C_{\text{ret}}$ ):$$C_{\text{ret}} = \Big[ (S_{\text{top}} \times 40) + (S_{\text{avg}} \times 30) + (D_{\text{score}} \times 15) + (M_{\text{meta}} \times 15) \Big] \times M_{\text{count}}$$ (Evaluating top similarity, average similarity, score decay distribution, metadata completeness, and candidate count ratio). -
Analysis Confidence (
$C_{\text{ana}}$ ): Weighted composite of Retrieval Confidence (50%), Analysis Completeness (30%), and Claim Overlap Density (20%). -
Overall Confidence:
$0.40 \times C_{\text{ret}} + 0.60 \times C_{\text{ana}}$ , mapped to qualitative tiers (Very High, High, Moderate, Low, Very Low).
6. Why use both PostgreSQL (Prisma) and Pinecone (Polyglot Persistence)?
- Specialized Workloads: Pinecone handles high-throughput Approximate Nearest Neighbor (ANN) cosine distance queries over 768-dimensional float vectors with serverless scaling.
- Relational ACID Integrity: PostgreSQL handles structured search sessions, user profiles, audit timestamps, and one-to-many relationships between search queries, retrieved patents, and novelty analysis reports via Prisma ORM.
- Resource Isolation: Vector search computations in Pinecone never compete with PostgreSQL transactional operations for memory or CPU.
7. How do you handle 50-page patent specifications within LLM context windows?
- Domain-Aware Section Extraction: During dataset ingestion (
extractPatentSections.ts), we isolate the highest-density legal sections: the Title, Abstract, and Independent Claims (which define the actual legal boundaries of protection). - Chunking with Sliding Windows: Detailed descriptions are chunked into 512-token segments with 50-token overlap, tagged with metadata (
patentId,section,ipc), ensuring only the most relevant sections enter the RAG prompt context.
8. How do you measure retrieval quality (Precision@K, Recall@K, MRR, NDCG)?
Through the automated benchmarking suite (POST /api/search/benchmark):
- Precision@K: Proportion of retrieved patents in the top-K that are relevant.
- Recall@K: Proportion of all known relevant patents found in the top-K.
-
MRR (Mean Reciprocal Rank): Reciprocal rank (
$\frac{1}{\text{rank}}$ ) of the first relevant patent found. - NDCG@K: Ranking quality metric that penalizes placing relevant patents at lower ranks using logarithmic discounting.
9. How does the Dependency Injection (DI) system work in Fastify?
In src/plugins/di.plugin.ts, we register a Fastify plugin that instantiates providers, repositories, services, and controllers in topological dependency order. The assembled container is decorated onto the Fastify instance as fastify.diContainer. This eliminates global state, enables clean unit testing with mocked providers, and enforces separation of concerns.
10. How would you scale this architecture to 100M patents and 5,000 QPS?
- Vector Sharding: Horizontally partition the Pinecone index across pod replicas for distributed read throughput.
- Query Caching: Deploy a Redis cache layer (
ENABLE_QUERY_CACHE=true) with a 300s TTL for popular query embeddings. - High-Throughput LLM Serving: Transition from single-node Ollama to a distributed vLLM cluster with PagedAttention and continuous batching behind an internal load balancer.
- Stateless Fastify Pods: Deploy Fastify as autoscaling stateless pods in Kubernetes (EKS/GKE) with horizontal pod autoscaling (HPA).
- Database Read Replicas: Direct search history and analytics reads to PostgreSQL read replicas.
| Parameter | Value / Metric | Description |
|---|---|---|
| Embedding Model | nomic-embed-text |
768 float dimensions, Cosine distance metric |
| Generative Model | qwen2.5:3b |
Local Ollama inference for RAG novelty analysis |
| RRF Parameters |
|
Reciprocal Rank Fusion constants (dense + BM25) |
| Retrieval Latency | Combined embedding generation + Pinecone query | |
| RAG Inference Latency | Concurrent novelty and claim overlap analysis | |
| Confidence Formula | Composite multi-factor confidence scoring |
PatentIQ/
βββ apps/
β βββ client/ # React 19 Frontend SPA
β β βββ src/
β β β βββ components/ # UI components (ResultCard, ConfidenceDashboard, 3D Canvas)
β β β βββ pages/ # Search, Results, History, HowItWorks, Docs
β β β βββ services/ # REST API service client integrations
β β β βββ types/ # TypeScript type definitions
β β βββ package.json
β β
β βββ server/ # Fastify Backend API Server
β βββ src/
β β βββ common/ # Middleware, DTO schemas, custom error classes
β β βββ config/ # Environment variables & service configs
β β βββ modules/ # Clean Architecture feature modules
β β β βββ admin/ # System metrics & admin management
β β β βββ analytics/ # Usage & performance telemetry
β β β βββ auth/ # JWT Authentication & user authorization
β β β βββ confidence/ # Confidence scoring heuristic module
β β β βββ embeddings/ # Vector embedding generation & batching
β β β βββ history/ # Search & RAG analysis persistence
β β β βββ patents/ # Patent ingestion & dataset processing
β β β βββ rag/ # RAG novelty analysis & candidate ranking
β β β βββ reports/ # Report generation & exports
β β β βββ search/ # Pinecone semantic search & filtering
β β β βββ uploads/ # PDF document parsing & extraction
β β β βββ users/ # User profile management
β β βββ plugins/ # Fastify core plugins & DI container
β β βββ providers/ # Vector DB & LLM provider implementations
β β βββ app.ts # Fastify application factory
β βββ tests/ # Unit & integration test suites
β βββ package.json
β
βββ docs/ # Deep-dive architecture & API technical guides
βββ README.md
Detailed technical specifications and architectural guides are available in the docs/ directory:
| Document | Description |
|---|---|
| π Interview & System Guide | End-to-end workflows, system design, math formulas & 26 technical interview Q&A |
| ποΈ System Architecture | Clean Architecture, Dependency Injection container, and request lifecycle |
| π REST API Specifications | Request/response DTO schemas, endpoints, and OpenAPI specs |
| π Semantic Search Pipeline | Vector embedding generation, Pinecone index querying, and metadata filters |
| π€ RAG Novelty Pipeline | 7-section structured prompts, claim overlap matrix, and anti-hallucination rules |
| π Benchmarking & Metrics | Precision@K, Recall@K, MRR, NDCG calculation, and latency percentiles |
| βοΈ Configuration Reference | Detailed breakdown of environment variables and service credentials |
| π Deployment Guide | Local environment setup, database migrations, and operational guidelines |
| π Project Structure Taxonomy | Directory taxonomy, module relationships, and contribution standards |
Ensure you have the following installed on your system:
- Node.js:
v20+ - npm (or pnpm)
- PostgreSQL:
v15+ - Ollama: Running locally with required models:
ollama pull nomic-embed-text ollama pull qwen2.5:3b
- Pinecone Account: API Key and an index configured (
dimension: 768,metric: cosine)
- Copy
.env.exampleinsideapps/server/to.env:
cp apps/server/.env.example apps/server/.env- Configure environment variables in
apps/server/.env:
NODE_ENV=development
PORT=4000
HOST=0.0.0.0
# Database Connection
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/patent_iq?schema=public"
# JWT Authentication
JWT_SECRET="patentiq_super_secret_jwt_key_2026"
# Pinecone Vector DB
PINECONE_API_KEY="your-pinecone-api-key"
PINECONE_INDEX_NAME="patent-embeddings"
# Ollama Local LLM & Embedding Models
OLLAMA_BASE_URL="http://localhost:11434"
OLLAMA_EMBEDDING_MODEL="nomic-embed-text"
OLLAMA_LLM_MODEL="qwen2.5:3b"
# File Storage & Search Defaults
STORAGE_TYPE="local"
STORAGE_PATH="./storage/uploads"
DEFAULT_TOP_K=10
BENCHMARK_ITERATIONS=5
ENABLE_QUERY_CACHE=false
CACHE_TTL_SECONDS=300Install workspace dependencies from the project root:
npm installRun Prisma migrations to initialize PostgreSQL database schemas:
cd apps/server
npx prisma migrate dev --name init
npx prisma generateStart the Fastify backend server and React frontend client:
# Start Backend API Server (Runs on http://localhost:4000)
cd apps/server
npm run dev
# Start Frontend UI Client (Runs on http://localhost:5173)
cd apps/client
npm run devPatentIQ includes built-in CLI scripts in apps/server to process, embed, and benchmark patent datasets:
cd apps/server| Script Command | Purpose & Description |
|---|---|
npm run clean-dataset |
Cleans raw CSV/JSON patent datasets and normalizes metadata schemas |
npm run extract-sections |
Extracts claims, abstracts, descriptions, and metadata into structured JSON |
npm run generate-embeddings |
Generates 768-dim vector embeddings for extracted sections via Ollama |
npm run upload-pinecone |
Batch uploads processed vector embeddings and metadata to Pinecone |
npm run semantic-search |
Executes interactive CLI test queries against the Pinecone vector index |
npm run benchmark-search |
Measures Precision@K, Recall@K, MRR, NDCG, and latency metrics |
Interactive OpenAPI / Swagger documentation is available when the server is running at:
π http://localhost:4000/documentation
POST /api/v1/search: Vector similarity search with optional metadata filters (IPC, country, date, assignee).POST /api/v1/search/benchmark: Execute multi-query benchmarking and return IR quality metrics.POST /api/v1/search/prior-art: Execute prior art evaluation over query.POST /api/v1/rag/analyze: Perform 7-section RAG novelty analysis & section/claim overlap breakdown.POST /api/v1/rag/rank: Hybrid candidate reranking over retrieved prior-art candidates.
POST /register: Register a new user account.POST /login: Authenticate and receive JWT access/refresh tokens.POST /refresh: Refresh expired access tokens.POST /logout: Invalidate user session tokens.
GET /: Retrieve paginated search history sessions for user.GET /:id: Fetch detailed search session, prior art matches, and RAG reports.DELETE /:id: Delete search session entry.
POST /api/v1/patents: Ingest new patent record into relational database.GET /api/v1/patents: List ingested patents with metadata pagination.GET /api/v1/patents/:id: Retrieve detailed patent by ID.POST /api/v1/uploads: Upload and parse patent PDF documents for instant prior-art analysis.
POST /api/v1/embeddings/generate: Generate vector embedding for input text.POST /api/v1/embeddings/batch: Batch vector embedding generation.GET /api/v1/admin/status: System operational status and index stats.POST /api/v1/admin/clear-cache: Purge active query response cache.GET /api/v1/analytics/overview: Usage statistics, query performance, and retrieval latency metrics.
GET /health: Overall server health and operational status.GET /health/postgres: PostgreSQL database connectivity status.GET /health/pinecone: Pinecone vector store API status.GET /health/ollama: Ollama local LLM service status.
PatentIQ features an evaluation module designed to measure retrieval efficiency and execution latency:
- Precision@K & Recall@K: Evaluates top-K document relevance against ground-truth benchmarks.
- MRR (Mean Reciprocal Rank): Evaluates the rank placement of the first relevant patent result.
- NDCG (Normalized Discounted Cumulative Gain): Measures ranked retrieval effectiveness.
- System Latency Instrumentation: Benchmarks execution time breakdown across embedding generation, vector similarity search, and database persistence (P95 / P99 latency percentiles).
Run backend unit and integration test suites using Vitest:
cd apps/server
# Run all unit tests
npm run test:unit
# Run integration tests
npm run test:integration
# Run full test coverage report
npm run test:coverageThis project is licensed under the ISC License.
Automated patent prior-art search engine using semantic similarity S