Skip to content

Repository files navigation

InterviewPrepSLM

A fully local, offline RAG (retrieval-augmented generation) system for interview Q&A. No training required — it retrieves the closest matching Q&A pairs to a question and asks a small local model to phrase the answer.

How it works

User question
    -> embed it (all-minilm via Ollama)
    -> find closest Q&A pairs (in-memory cosine similarity search)
    -> hand those pairs + the question to a small local chat model (phi3 via Ollama)
    -> return the generated answer

Project layout

  • InterviewPrepSLM.Core — the actual RAG engine. No console/UI code here, so it can be reused inside a Web API, an agent tool, a background service, anything.
    • Models/QAPair.cs — the Q&A data shape
    • Retrieval/CosineSimilarity.cs — vector comparison, pure function
    • Retrieval/InMemoryVectorStore.cs — brute-force nearest-neighbor search
    • QAAgent.cs — orchestrator: embed → search → generate
  • InterviewPrepSLM.Console — a console host you can run and chat with directly.
  • InterviewPrepSLM.Tests — xUnit tests for the retrieval logic, using a fake embedding generator so tests don't need Ollama running.
  • data/qa-pairs.json — your Q&A pairs. Add as many as you want; the schema is question, answer, category (optional), tags (optional).

Setup

  1. Install Ollama (runs models fully offline once downloaded): https://ollama.com/download

  2. Pull the two models this project uses:

    ollama pull all-minilm
    ollama pull phi3
    

    all-minilm turns text into vectors for search. phi3 writes the final answer. Both run on CPU; a GPU just makes them faster.

  3. Restore and build:

    dotnet restore
    dotnet build
    
  4. Run the tests (no Ollama needed for these — they use a fake embedder):

    dotnet test
    
  5. Run the console app (Ollama must be running in the background):

    dotnet run --project InterviewPrepSLM.Console
    

Adding your own Q&A pairs

Edit data/qa-pairs.json — each entry just needs question and answer. category and tags are optional and not used by search yet, but are there if you want to filter or group later.

Using this from an AI agent

Any agent/tool framework just needs to call QAAgent.AskAsync(question) — that's the entire public surface. Wrap it in a Web API controller, an MCP tool, or a plain method call; the RAG logic doesn't care about the caller.

Scaling notes

  • More than a few thousand Q&A pairs: swap InMemoryVectorStore for a real vector store (e.g. pgvector, Qdrant, Azure AI Search) behind the same IVectorStore interface — nothing else in the app changes.
  • Want a different model or provider: QAAgent depends on IEmbeddingGenerator<string, Embedding<float>> and IChatClient, both from Microsoft.Extensions.AI. OllamaSharp implements both, but so do other providers (Azure OpenAI, OpenAI, etc.) — swap the implementation in Program.cs only.
  • Want the model to actually "learn" your material rather than retrieve it: that's fine-tuning, a separate step from this RAG setup. Worth doing once you have a larger, well-reviewed dataset — this RAG pipeline is a good source of that data since you'll see which retrieved answers needed the most rephrasing.

A note on package versions

OllamaSharp and the Microsoft.Extensions.AI abstractions it implements are both actively evolving. If a method name doesn't match what's in this code, check IntelliSense or the OllamaSharp GitHub repo — the shape shown here matches the versions current as of mid-2026.

About

Fully local .NET RAG assistant using Ollama, embeddings, cosine similarity, testable abstractions, and in-memory vector search.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages