8 Downloads
8 Downloads
A modified version of the RAG v1, preprocessor plugin for LM Studio, built for SAIC.
This is a fork of Oobioobi's context-aware-rag plugin for LM Studio.
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.
OCR supports English and Russian out of the box (configurable via the OCR Language plugin setting: eng, rus, or eng+rus). The Tesseract language data (eng.traineddata, rus.traineddata) is versioned in this repo so no network download happens at runtime.
A modified version of the RAG v1, preprocessor plugin for LM Studio, built for SAIC.
This is a fork of Oobioobi's context-aware-rag plugin for LM Studio.
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.
OCR supports English and Russian out of the box (configurable via the OCR Language plugin setting: eng, rus, or eng+rus). The Tesseract language data (eng.traineddata, rus.traineddata) is versioned in this repo so no network download happens at runtime.
npm run download β fetches both eng and rus .traineddata files (the 4.0.0_fast builds from naptha/tessdata) into the project root.npm run install-plugin β runs the download first, then installs the plugin to LM Studio and copies the language files into the plugin's install directory.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.OCR Language setting (eng, rus, or eng+rus). Both eng and rus language data ship with the repo, so tesseract.js downloads nothing on first use."eng" language pack, but this is now configurable via the OCR Language plugin setting (eng, rus, or eng+rus). Both language files ship with the plugin, so no network fetch is needed on first OCR..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.npm run download β fetches both eng and rus .traineddata files (the 4.0.0_fast builds from naptha/tessdata) into the project root.npm run install-plugin β runs the download first, then installs the plugin to LM Studio and copies the language files into the plugin's install directory.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.OCR Language setting (eng, rus, or eng+rus). Both eng and rus language data ship with the repo, so tesseract.js downloads nothing on first use."eng" language pack, but this is now configurable via the OCR Language plugin setting (eng, rus, or eng+rus). Both language files ship with the plugin, so no network fetch is needed on first OCR..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.