Project Files
README.md
A modified version of the RAG v1, preprocessor plugin for LM Studio, built for SAIC.
This plugin intercepts incoming user messages with attachments, analyzes the available model context window, and dynamically determines the best strategy to inject or retrieve relevant document dataβincluding an automated OCR fallback for flat or scanned PDFs.
Automatically measures your active LLM context window. Routes documents to either inject-full-content (if they easily fit) or retrieval (vector search chunking) based on a customizable occupancy threshold.
Scans text length of ingested PDFs. If a document appears to be a flat image or scanned file, it triggers a local OCR parsing pipeline using a custom buffer wrapper.
Uses a global file-path-based memory map to cache extracted text across your entire chat session. Documents are parsed and OCR'd exactly once, eliminating redundant lag on subsequent conversation turns.
Combines native LM Studio document retrieval results with custom vector embeddings computed on OCR-recovered content using the Nomic embedding model.
chooseContextInjectionStrategy) β measures the model's context window, occupied %, and total tokens across attached files + prompt. Picks inject-full-content if everything fits under a 70%-of-remaining-context budget, otherwise picks retrieval.prepareDocumentContextInjection) β parses each file and inlines its full text directly into the prompt.prepareRetrievalResultsContextInjection) β runs native LM Studio file retrieval for normally-parsed files, and custom chunk + cosine-similarity scoring (via Nomic embeddings) for custom-parsed (OCR/pptx) files. Merges both, filters by affinity threshold, sorts by score, and slices to the configured retrieval limit.parserChain / parserIndex) β ordered fallback chain per file:
.pdf only) β triggers if the native parser's text is under 50 chars<a:t> text runs + speaker notes directly from slide XML<w:t> text runs (paragraphs + table cells) + headers/footers directly from document XMLglobalCache in parseFile.ts) β keyed by resolved file path, holds parsed text and (lazily) computed chunk embeddings for the life of the plugin process. Failures are never cached, so a transient error can be retried."eng" language pack; scanned non-English PDFs will produce garbled or empty text rather than failing cleanly..csv, .md, etc.) depends entirely on whatever LM Studio's native files.parseDocument supports; there's no custom fallback for those.<a:t>/<w:t> runs) yield no extracted text; images/diagrams are never OCR'd for these formats (only flat/scanned PDFs get the OCR fallback).file.name when no path is available) will collide in the cache.nomic-ai/nomic-embed-text-v1.5-GGUF; it isn't configurable.