Hirarish.RagKit 0.6.0

dotnet add package Hirarish.RagKit --version 0.6.0
                    
NuGet\Install-Package Hirarish.RagKit -Version 0.6.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hirarish.RagKit" Version="0.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hirarish.RagKit" Version="0.6.0" />
                    
Directory.Packages.props
<PackageReference Include="Hirarish.RagKit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hirarish.RagKit --version 0.6.0
                    
#r "nuget: Hirarish.RagKit, 0.6.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Hirarish.RagKit@0.6.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hirarish.RagKit&version=0.6.0
                    
Install as a Cake Addin
#tool nuget:?package=Hirarish.RagKit&version=0.6.0
                    
Install as a Cake Tool

RagKit

Lightweight Retrieval-Augmented Generation (RAG) toolkit in a single DLL:

  • Local ONNX embeddings (SentenceTransformers all-MiniLM-L6-v2) — no per-call embedding fees, low latency, data stays on-prem.
  • Fast in-memory vector index for retrieval.
  • SQL ingestion helpers (batch + async).
  • Cost estimation utilities.
  • Optional OpenAI chat helpers with strict grounding (answer only from retrieved context).

Table of Contents


What problems does RagKit solve?

  1. Cost & latency of embeddings
    Hosted APIs are expensive & slow. RagKit runs local SentenceTransformers via ONNX Runtime: free per call, and fast (ms scale).

  2. Simple RAG pipeline without stack explosion
    No need for a separate vector DB. RagKit gives you an in-memory index, SQL ingestion, chunking, retrieval, and OpenAI helpers.

  3. Data residency & privacy
    Embed & search locally, send only retrieved snippets (not full docs) to OpenAI.

  4. Predictable spend
    Estimate token costs for "send everything" vs. "retrieve top-k context".


When should I use RagKit?

✅ Use RagKit if:

  • You want a drop-in .NET RAG library.
  • Your corpus fits in memory (or you persist/load compact indexes).
  • You need a SQL → embeddings → retrieval → (optional) LLM flow.

❌ Don’t use RagKit if:

  • You need billions of vectors / sharding → use a vector DB.
  • You need multilingual SOTA embeddings → use a multilingual ONNX model (RagKit is model-agnostic).

Key features

  • Local embeddings: ONNX Runtime (CPU/CUDA/DirectML).
  • Tokenizer: Microsoft.ML.Tokenizers (WordPiece).
  • Indexing: in-memory w/ cosine similarity, save/load JSON.
  • SQL ingest: stream, chunk, batch embed.
  • Retrieval: top-k results w/ scores.
  • OpenAI (optional): grounded answers.
  • Cost estimator: RAG vs. full-document.

Install

dotnet add package Hirarish.RagKit


Quick Start

using System; using RagKit;

var rag = new RAGClient();

// Index content rag.AddText("policy-01", "Refunds are available within 30 days of purchase with a valid receipt."); rag.AddText("policy-02", "Exchanges can be made up to 60 days after the original purchase.");

// Retrieve locally var hits = rag.Retrieve("what is the refund policy?");

foreach (var (chunk, score) in hits) Console.WriteLine($"[Score: {score:F4}] {chunk.Id}: {chunk.Text}");


Configuration

Model Files

Defaults included in NuGet. Override with:

var options = new RAGOptions { ModelPath = Path.Combine(AppContext.BaseDirectory, "MyCustomModels"), Provider = ExecutionProvider.Cuda }; var rag = new RAGClient(options);

OpenAI API Key

Windows

setx OPENAI_API_KEY "sk-live-..."

Linux/macOS

export OPENAI_API_KEY="sk-live-..."

Or in code: var rag = new RAGClient(new RAGOptions { OpenAIApiKey = "sk-live-..." });


Usage Examples

SQL Ingest (async)

var rag = new RAGClient(); int chunks = await rag.AddSqlQueryAsync( connectionString: cs, sql: sql, idColumn: "ItemId", textColumn: "Content", sourceIdColumn: "Source", parameters: parameters, chunkRows: false );

Strict OpenAI (grounded answers only)

var rag = new RAGClient(); var answer = await rag.AskOpenAIStrictAsync("list tasks not completed yet"); Console.WriteLine(answer);

Example: Creating a Domain-Specific Helper

public string SummarizeTasks(IRAGClient rag, string query, int topK = 5) { var hits = rag.Retrieve(query, topK); if (hits.Count == 0) return "No relevant tasks found.";

var sb = new System.Text.StringBuilder();
sb.AppendLine($"Found {hits.Count} relevant tasks:");

foreach (var (chunk, score) in hits)
    sb.AppendLine($" - Task {chunk.SourceId}: {chunk.Text}");

return sb.ToString();

}

Cost Estimation

var ragCost = rag.EstimateRagCost("summarize tasks", topK: 5, predictedOutputTokens: 300); Console.WriteLine($"RAG Path Cost: ${ragCost.TotalUsd:F6}");

Persist / Reload Index

var rag = new RAGClient(); if (File.Exists("rag-index.json")) rag.LoadIndex("rag-index.json"); else { // ingest ... rag.SaveIndex("rag-index.json"); }


Options (RAGOptions)

  • Model: ModelPath, VocabPath, MaxLength, Provider, BatchSize
  • Retrieval: TopK, ChunkMaxChars, ChunkOverlapChars, ContextCharBudget
  • OpenAI: OpenAIModel, OpenAIApiKey
  • Pricing: CharsPerToken, Pricing

Troubleshooting

  • [UNK] not in vocabulary → wrong tokenizer file.
  • Model not found → check ModelPath.
  • OpenAI key missing → set OPENAI_API_KEY.
  • No results → index content before Retrieve().

How to pack & publish a new version

Bump version in .csproj

dotnet pack -c Release -p:PackageVersion=0.5.1 dotnet nuget push bin/Release/*.nupkg --api-key <NUGET_API_KEY> --source https://api.nuget.org/v3/index.json --skip-duplicate

Smoke test: dotnet new console -n RagKitSmokeTest cd RagKitSmokeTest dotnet add package Hirarish.RagKit --version <version>


License (MIT)

MIT License – free to use, modify, and distribute.

Copyright (c) 2025 Mobideo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.0 365 9/9/2025