๐Ÿ“š Vector DB Document Retrieval

SLM RAG

Local Retrieval-Augmented Generation engine for offline document indexing, dense vector search, and grounded Q&A.

๐Ÿš€ Overview & Capabilities

Local Retrieval-Augmented Generation engine for offline document indexing, dense vector search, and grounded Q&A.

Key Features

  • Offline ONNX embedding generation
  • Local vector similarity indexing
  • Grounded factual document question answering
  • Strict context window enforcement

๐Ÿ’ป Installation

Install the local package using pip:

Terminal
$pip install slm-rag

๐Ÿ™ Checkout from GitHub

Clone only this agent's folder from the monorepo using Git sparse-checkout โ€” no need to download the full repository:

Option 1 โ€” Sparse Checkout (Recommended)

Terminal โ€” Git Sparse Checkout
# 1. Create and enter a new directory
$ mkdir slm_rag && cd slm_rag

# 2. Initialise empty git repo and add remote
$ git init
$ git remote add origin https://github.com/t00114218-stack/SLMAgents.git

# 3. Enable sparse-checkout and set target folder
$ git sparse-checkout init --cone
$ git sparse-checkout set slm_rag

# 4. Pull only that agent's source
$ git pull origin main

Option 2 โ€” Full Repository Clone

Terminal โ€” Full Clone
$ git clone https://github.com/t00114218-stack/SLMAgents.git
$ cd SLMAgents/slm_rag

๐Ÿ’ก Tip: After checkout, install the package locally with pip install -e ./slm_rag to run in editable mode without publishing to PyPI.

โš™๏ธ Configuration API

Constructor Parameters

Instantiate SLMRag with performance and runtime options:

ParameterType / DefaultDescription
model_pathstr | NoneLocal ONNX model path. Default: None.
temperaturefloat | 0.0Sampling temperature. Default: 0.0.
top_pfloat | 0.9Nucleus sampling threshold. Default: 0.9.
max_tokensint | 256Maximum output token limit. Default: 256.
n_threadsint | 4CPU threads. Default: 4.

Methods

Method SignatureReturn TypeDescription
answer(question, chunks, ...)str | dictRetrieves matching context chunks and generates factual response.

Execution Parameters

Complete list of execution parameters accepted by the primary agent method:

ParameterType / DefaultDescription
questionstrUser question string.
chunkslist[str] | strDocument context text or chunk list.
instructionstr | NoneExtraction instruction guideline. Default: None.
system_promptstr | NoneSystem prompt instruction. Default: None.
user_inputstr | NoneContextual key values. Default: None.
temperaturefloat | 0.0Sampling temperature. Default: 0.0.
top_pfloat | 0.9Nucleus sampling probability. Default: 0.9.
max_tokensint | 256Maximum token limit. Default: 256.

Quick Start

Python Example
from slm_rag import SLMRag

rag = SLMRag(temperature=0.0, top_p=0.9, max_tokens=256)
res = rag.answer(
    question="What is total Q3 net revenue?",
    chunks="Q3 net revenue reached $1.25M., Due date: Sept 2026",
    instruction="Extract exact numerical totals",
    system_prompt="Factual document extraction",
    user_input="Currency: USD",
    temperature=0.0,
    top_p=0.9,
    max_tokens=256
)
print(res)

๐Ÿ” Verified Output Logs

Diagnostic execution console output running locally on CPU:

Output Console
โ†’ INPUT:
Question: What is total Q3 net revenue?

โ† OUTPUT:
{
  'status': '200 OK',
  'answer': 'Based on documents: Q3 net revenue is $1.25M USD.',
  'retrieved_chunks': 2
}