Skip to content

Korunil/stackfix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

21 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿž StackFix

Python LangChain FAISS Hugging Face RAG License

Built for realistic developer debugging workflows using hybrid retrieval + intelligent routing.

Focus areas: Hybrid Retrieval โ€ข Agentic Routing โ€ข Grounded Debugging โ€ข RAG Systems โ€ข Semantic Search

Agentic Hybrid AI Debugging System with Intelligent Local Retrieval and Live Internet Reasoning

StackFix Banner

StackFix is a hybrid AI debugging agent that combines local retrieval, reranking, intelligent routing, and live internet reasoning to solve real-world software engineering issues with grounded and source-aware responses.

Instead of relying entirely on live web search or raw LLM generation, StackFix intelligently decides whether a query can be solved using a locally indexed StackOverflow-style knowledge base or whether it should switch to live internet reasoning for newer ecosystem issues.

The system combines:

  • Semantic Retrieval (FAISS)
  • BM25 Lexical Search
  • Cross-Encoder Reranking
  • Query Refinement Agent
  • Confidence & Routing Agents
  • Live Internet Fallback
  • Source-Aware Response Generation

to provide grounded, practical, and developer-focused debugging assistance.


๐Ÿ“‘ Table of Contents


๐Ÿš€ Overview

Modern debugging assistants often struggle with:

  • hallucinated fixes
  • outdated package information
  • slow web reasoning
  • lack of source grounding
  • noisy retrieval results

StackFix addresses this by introducing a hybrid multi-agent debugging pipeline.

The system first attempts to solve queries using local retrieval over a curated debugging knowledge base. If retrieval confidence is insufficient, StackFix dynamically switches to live internet reasoning.

This enables:

  • โšก fast responses for known issues
  • ๐ŸŒ internet fallback for emerging ecosystem problems
  • ๐ŸŽฏ grounded retrieval-based debugging
  • ๐Ÿง  intelligent query routing
  • ๐Ÿ“š source-aware answers

StackFix is designed around realistic debugging workflows:

  • traceback-heavy issues
  • dependency conflicts
  • framework migration errors
  • CUDA/runtime failures
  • evolving package ecosystems
  • developer search behavior

โšก Quick Start

git clone https://github.com/Korunil/stackfix.git
cd stackfix

pip install -r requirements.txt

Download Prebuilt Indexes

Download FAISS + BM25 indexes from:

Hugging Face Dataset

Place them inside:

./model_cache/

Launch StackFix

chainlit run app.py

๐Ÿ’ก Why StackFix?

Most AI debugging assistants rely entirely on:

  • static retrieval
  • pure LLM generation
  • or expensive live web search

StackFix introduces an intelligent hybrid approach:

Problem StackFix Solution
Hallucinated fixes Grounded retrieval
Slow web debugging Fast local retrieval
Outdated package info Internet fallback
Weak ranking quality Cross-encoder reranking
Poor routing decisions Confidence + Routing Agents

The result is a debugging assistant that is:

  • faster
  • cheaper
  • more grounded
  • and more adaptive to modern software ecosystems.

Note: The reranker evaluates not only document content, but also titles, tags, and extracted code snippets to improve debugging relevance.


โœจ Features

  • ๐Ÿ”€ Intelligent routing between LOCAL and INTERNET modes
  • ๐Ÿง  Hybrid retrieval using FAISS + BM25
  • ๐ŸŽฏ Cross-encoder reranking
  • โšก Fast local debugging
  • ๐ŸŒ Live internet fallback
  • ๐ŸŒ Intelligent GitHub + web retrieval fallback
  • ๐Ÿ“š Source attribution
  • ๐Ÿงฉ Query refinement pipeline
  • ๐Ÿ–ฅ๏ธ Interactive Chainlit UI
  • ๐Ÿš€ GPU acceleration support
  • ๐Ÿงฎ Offload mode for lower VRAM systems
  • ๐Ÿ”ง SSL verification toggle support
  • ๐Ÿ“ฆ Prebuilt FAISS/BM25 index support

๐Ÿค– Agentic Pipeline

StackFix uses lightweight specialized agents internally to improve debugging quality. The agents are intentionally lightweight and modular, allowing StackFix to separate query understanding, confidence estimation, routing, and response generation into specialized responsibilities.


๐Ÿ”น Query Refinement Agent

Expands and enriches debugging queries before retrieval.

Example:

Original Query:
ModuleNotFoundError: No module named 'langchain_huggingface'

Refined Query:
ModuleNotFoundError langchain_huggingface import issue package installation dependency fix

Benefits:

  • better retrieval recall
  • improved semantic matching
  • stronger reranking quality

๐Ÿ”น Confidence Agent

Calculates how confidently the local knowledge base can answer a query.

Used for:

  • local retrieval confidence scoring
  • routing decisions
  • internet fallback triggering

Example:

Local Match: 0.96

๐Ÿ”น Routing Agent

Determines whether the query should use:

  • LOCAL retrieval OR
  • INTERNET reasoning

based on:

  • retrieval quality
  • rerank confidence
  • semantic relevance

This prevents:

  • unnecessary web search
  • hallucinated local answers
  • poor retrieval grounding

Example:

Route: LOCAL
Local Match: 0.96

or

Route: INTERNET
Local Match: 0.42

๐Ÿ’ป System Requirements

Recommended:

  • Python 3.11
  • CUDA-enabled GPU
  • 32GB+ RAM
  • 10GB+ free storage for indexes

โš ๏ธ Loading full retrieval indexes may require substantial RAM depending on FAISS configuration and BM25 size.

Minimum:

  • CPU-only supported via OFFLOAD_MODE
  • Lower RAM systems may experience slower retrieval/reranking

๐Ÿ“ˆ Performance Characteristics

Mode Typical Latency
LOCAL Retrieval Low latency
INTERNET Mode Higher latency
Preloaded Models Faster warm inference
Offload Mode Reduced VRAM, slower responses

Performance depends on:

  • hardware
  • GPU availability
  • dataset size
  • reranker configuration

๐Ÿ—๏ธ Architecture

StackFix intentionally separates retrieval confidence estimation from final response generation.

This allows routing decisions to remain lightweight, interpretable, and modular while preventing expensive internet reasoning for queries that can already be solved locally with high confidence.

Key architectural goals:

  • minimize unnecessary internet reasoning
  • improve debugging grounding quality
  • balance semantic and lexical retrieval
  • reduce hallucinated fixes
  • optimize retrieval latency for known issues

Architecture


๐Ÿ”€ Flowchart

flowchart TD

    A[User Query]
    --> B[Query Refinement Agent]

    B --> C[Confidence + Routing Agents]

    C -->|LOCAL| D[Hybrid Retriever]

    D --> E[BM25 Retrieval]
    D --> F[Vector Retrieval]

    E --> G[Cross-Encoder Reranker]
    F --> G

    G --> H[Context Builder]
    H --> I[LLM Generator]

    C -->|INTERNET| J[Live Web Search]
    J --> K[Web Context Builder]
    K --> I

    I --> L[Grounded Response + Sources]
Loading

๐Ÿ”„ Retrieval Pipeline

LOCAL MODE

  1. User submits debugging query
  2. Query Refinement Agent expands the query
  3. Confidence Agent estimates retrieval confidence
  4. Routing Agent selects LOCAL mode
  5. Hybrid retrieval fetches:
    • semantic results (FAISS)
    • lexical results (BM25)
  6. Results are deduplicated
  7. Cross-encoder reranks documents
  8. Top documents are converted into structured context
  9. LLM generates grounded debugging response
  10. Source attribution is attached

๐Ÿ“Š Retrieval Quality Snapshot

Retrieval Strategy Strength
FAISS Only Strong semantic similarity matching
BM25 Only Strong exact traceback and keyword matching
Hybrid Retrieval Better overall debugging recall
Hybrid + Reranking Highest contextual relevance and grounding quality

This hybrid retrieval design helps StackFix balance:

  • semantic understanding
  • exact error matching
  • contextual relevance
  • grounded debugging responses

๐ŸŒINTERNET MODE

Activated when:

  • local confidence is insufficient
  • issue is too recent
  • framework/library is evolving
  • retrieval quality is weak

Pipeline:

  1. Query refinement
  2. Routing to internet mode
  3. Live web search
  4. Context extraction
  5. LLM reasoning
  6. Structured debugging response

๐ŸŒ Intelligent External Retrieval

When LOCAL retrieval confidence is low, StackFix performs structured external retrieval using:

  • GitHub issue search
  • trusted technical web sources
  • signal-aware query construction
  • heuristic scoring and ranking

The external retrieval pipeline prioritizes:

  • framework/package relevance
  • traceback overlap
  • exact dependency matches
  • trusted engineering domains

This helps improve:

  • grounding quality
  • debugging relevance
  • retrieval precision
  • modern ecosystem issue handling

๐Ÿ“‚ Repository Structure

stackfix/
โ”‚
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ config.py
โ”œโ”€โ”€ cache_store.py
โ”œโ”€โ”€ preload.py
โ”œโ”€โ”€ requirements.txt
โ”‚
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ citation_builder.py
โ”‚   โ”œโ”€โ”€ query_parser.py
โ”‚   โ”œโ”€โ”€ query_builder.py
โ”‚   โ”œโ”€โ”€ query_expander.py
โ”‚   โ”œโ”€โ”€ query_fallback.py
โ”‚   โ”œโ”€โ”€ github_search.py
โ”‚   โ””โ”€โ”€ web_search.py
โ”‚
โ”œโ”€โ”€ agents/
โ”‚   โ”œโ”€โ”€ refinement_agent.py
โ”‚   โ”œโ”€โ”€ confidence_agent.py
โ”‚   โ””โ”€โ”€ routing_agent.py
โ”‚
โ”œโ”€โ”€ rag/
โ”‚   โ”œโ”€โ”€ ingestion.py
โ”‚   โ”œโ”€โ”€ embedding.py
โ”‚   โ”œโ”€โ”€ vector_store.py
โ”‚   โ”œโ”€โ”€ bm25_store.py
โ”‚   โ”œโ”€โ”€ hybrid_retriever.py
โ”‚   โ””โ”€โ”€ reranker.py
โ”‚
โ”œโ”€โ”€ pipeline/
โ”‚   โ””โ”€โ”€ debug_pipeline.py
โ”‚
โ”œโ”€โ”€ prompts/
โ”‚	โ”œโ”€โ”€ debug_prompt.py
โ”‚   โ”œโ”€โ”€ fallback_prompt.py
โ”‚   โ”œโ”€โ”€ system_prompt.py
โ”‚   โ””โ”€โ”€ system_prompt_detailed.py
โ”‚
โ”œโ”€โ”€ llm/
โ”‚	โ”œโ”€โ”€ llm.py
โ”‚   โ””โ”€โ”€ generator.py
โ”‚
โ”œโ”€โ”€ memory/
โ”‚   โ””โ”€โ”€ memory.py
โ”‚
โ”œโ”€โ”€ model_cache/
โ”‚   โ”œโ”€โ”€ faiss_index/
โ”‚   โ””โ”€โ”€ bm25_index.pkl
โ”‚
โ”œโ”€โ”€ datasets/
โ”‚   โ”œโ”€โ”€ raw/
โ”‚   โ”‚	โ””โ”€โ”€ instructions.txt
โ”‚   โ””โ”€โ”€ processed/
โ”‚   	โ””โ”€โ”€ sample_stackoverflow.jsonl
โ”‚
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ preprocess_dataset.py
โ”‚   โ””โ”€โ”€ generate_report.py
โ”‚
โ”œโ”€โ”€ assets/
โ”œโ”€โ”€ public/
โ”‚
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ chainlit_en-US.md
โ””โ”€โ”€ README.md

๐ŸŽฅ Demo Videos

๐Ÿ”น Quick Demo (Recommended)

Edited showcase version with:

  • annotations
  • walkthrough
  • transitions
  • music
  • faster pacing

๐Ÿ“น Watch Quick Demo


๐Ÿ”น Full Demo (Raw Performance)

Complete unedited walkthrough showing:

  • LOCAL retrieval
  • INTERNET fallback
  • CUDA OOM debugging

๐Ÿ“น Watch Full Demo


๐Ÿ–ฅ๏ธ UI Walkthrough

๐Ÿ”น Landing Screen

Landing Screen


๐Ÿ”น LOCAL Retrieval Walkthrough

Known debugging issue solved using local retrieval pipeline.

LOCAL Query


๐Ÿ”น INTERNET Fallback Walkthrough

Recent ecosystem issue automatically routed to internet reasoning.

INTERNET Query


๐Ÿ”น CUDA OOM Debugging Example

GPU memory issue solved using intelligent fallback and debugging reasoning.

CUDA OOM Query


โšก Preloading Models

StackFix supports preloading:

  • embedding models
  • rerankers
  • vector indexes

This significantly reduces runtime latency.

Example:

preload_retriever()

Benefits:

  • faster query responses
  • avoids cold starts
  • smoother demos

โš™๏ธ Configuration Guide

Main configurable parameters inside config.py:

Parameter Description
K Initial retrieval count
TOP_K Final reranked documents
FETCH_K Documents fetched before reranking
BATCH_SIZE Cross-encoder batch size
BM25_WEIGHT Lexical retrieval weight
VECTOR_WEIGHT Semantic retrieval weight
ROUTING_THRESHOLD Local vs internet routing threshold
DEVICE_RERANKER CPU/GPU reranker device
OFFLOAD_MODE Enables low VRAM loading
SSL_VERIFY Toggle SSL verification

๐Ÿงฎ Offload Mode

For lower VRAM systems:

OFFLOAD_MODE = True

Benefits:

  • reduced GPU memory usage
  • CPU offloading support
  • smaller GPU compatibility

Tradeoff:

  • slower inference

๐Ÿ”“ SSL Verification Toggle

Useful for restricted enterprise/corporate environments.

SSL_VERIFY = False

โš ๏ธ Recommended only for development/testing.


๐Ÿ“š Dataset

StackFix uses the public StackSample dataset from Kaggle containing:

  • programming questions
  • accepted answers
  • code snippets
  • tags
  • metadata

Included:

  • lightweight sample dataset

Excluded:

  • full production-scale dataset due to repository size constraints

๐Ÿ“Š Dataset Statistics

  • Total Documents: 1,102,568 Q&A Pairs
  • Quality Threshold: Only the highest-scored answer per question was retained.
  • Global Average SO Score: 3.31
  • Top 10 Tags/Languages: javascript, java, c#, php, android, jquery, python, html, c++, ios

๐Ÿง  Embedding Architecture

  • Model: BAAI/bge-base-en-v1.5
  • Dimensions: 768
  • Normalization: True (Cosine Similarity optimized)
  • Context Strategy: Questions, answers, and code blocks are merged into a single text block (retrieval_text).

๐Ÿ“ฅ How to Generate the Indexes

  1. Download the Kaggle StackSample dataset from link:Kaggle StackSample Dataset.
  2. Place the csv files inside your ./datasets/raw/ directory.
  3. Run ./scripts/preprocess_dataset.py to start generation of stackoverflow.jsonl.
  4. chainlit run app.py. The system will automatically detect the files.

๐Ÿค— Prebuilt Retrieval Indexes and Full Dataset

To avoid regenerating embeddings and indexes locally, StackFix provides prebuilt retrieval artifacts hosted on Hugging Face.

Due to GitHub file size limitations, the full StackFix retrieval artifacts are hosted on Hugging Face.

๐Ÿ“ฅ Download

Hugging Face Repository:

Hugging Face Dataset

Included:

  • FAISS vector indexes
  • BM25 retrieval index
  • Processed StackOverflow retrieval dataset

These prebuilt indexes allow StackFix to start instantly without requiring multi-hour embedding generation.

๐Ÿ“ฆ Included Files

File Description
faiss_index/ Prebuilt FAISS vector indexes
bm25_index.pkl Serialized BM25 retrieval index
stackoverflow.jsonl Processed retrieval dataset

๐Ÿš€ Usage

Place the downloaded files inside:

./model_cache/

Then launch StackFix normally:

chainlit run app.py

The system will automatically detect and load the indexes.


โšก Performance Notes

  • Prebuilt FAISS and BM25 indexes dramatically reduce startup time.
  • Initial indexing over 1M+ StackOverflow entries can take significant time and storage.
  • GPU acceleration is recommended for embedding generation and reranking.
  • Offload mode enables operation on lower VRAM systems.

๐Ÿท๏ธ Source Attribution

Responses include source grounding and attribution.

Example:

๐Ÿ“š Sources:
[1] TypeError: Can't convert 'int' object to str implicitly

Benefits:

  • transparency
  • trustworthiness
  • grounded debugging

๐Ÿงช Example Queries

LOCAL Retrieval Example

I am getting TypeError: can only concatenate str (not "int") to str when trying to print a user's age with a string. How do I fix this?

INTERNET Fallback Example

I just upgraded my pipeline and I am getting ModuleNotFoundError: No module named 'langchain_huggingface'. How do I fix this?

GPU Debugging Example

I am getting RuntimeError: CUDA out of memory while training my PyTorch model. How do I reduce GPU memory usage?

๐Ÿงฐ Tech Stack

Component Technology
UI Chainlit
Framework LangChain
Vector Search FAISS
Lexical Search BM25
Reranking SentenceTransformers
Embeddings HuggingFace
Language Python
Inference PyTorch

โ–ถ๏ธ Running Locally

1๏ธโƒฃ Clone Repository

git clone https://github.com/Korunil/stackfix.git
cd stackfix

2๏ธโƒฃ Install Dependencies

pip install -r requirements.txt

โšก Recommended Setup (Fast Startup)

Download prebuilt FAISS + BM25 indexes from:

Hugging Face Dataset

Place the downloaded files inside:

./model_cache/

Structure example:

model_cache/
โ”œโ”€โ”€ faiss_index/
โ””โ”€โ”€ bm25_index.pkl

This avoids regenerating embeddings locally and dramatically reduces setup time.


๐Ÿ› ๏ธ Full Local Index Generation (Optional)

If you want to build the indexes yourself:

1. Download StackSample Dataset

Download from:

Kaggle StackSample Dataset


2. Place CSV Files

Move the downloaded CSV files into:

./datasets/raw/

3. Generate Processed Dataset

python ./scripts/preprocess_dataset.py

4. Launch StackFix

chainlit run app.py

The system will automatically:

  • generate embeddings
  • build FAISS indexes
  • build BM25 indexes
  • cache retrieval artifacts

๐Ÿง  Key Insights

Why Hybrid Retrieval?

Semantic search alone may:

  • miss exact error strings
  • struggle with tracebacks

BM25 alone may:

  • miss conceptual similarity

Combining both improves:

  • recall
  • robustness
  • debugging quality

Why Cross-Encoder Reranking?

Initial retrieval often contains noisy candidates.

Cross-encoder reranking significantly improves:

  • contextual relevance
  • grounding quality
  • response precision

Why Intelligent Routing?

Not every debugging problem should use live internet reasoning.

Local retrieval provides:

  • speed
  • determinism
  • reduced hallucination risk

Internet fallback handles:

  • evolving frameworks
  • recent package changes
  • new ecosystem issues

โš™๏ธ Limitations

  • Internet mode depends on external web quality
  • Retrieval quality depends on dataset coverage
  • Very recent ecosystem issues may lack grounding
  • Large-scale indexing requires significant storage
  • Some fixes may still require manual verification

๐Ÿ”ฎ Future Work

  • VSCode extension
  • Docker deployment
  • Better traceback parsing
  • Multi-hop debugging
  • Dependency conflict detection
  • Agentic debugging workflows
  • Query expansion improvements

๐Ÿค Contributing

Contributions, ideas, and feedback are welcome!

Suggested areas:

  • retrieval improvements
  • reranking optimization
  • dataset quality
  • UI enhancements
  • evaluation benchmarks
  • routing logic

๐Ÿ“œ License

Licensed under the Apache 2.0 License.


โญ Support the Project

If you found this project useful:

  • Star the repository
  • Open issues
  • Suggest improvements
  • Share feedback

๐Ÿ”— Repository

https://github.com/Korunil/stackfix.git


๐Ÿ™Œ Acknowledgements

Built using open-source tooling from:

  • LangChain
  • Chainlit
  • FAISS
  • Sentence Transformers
  • Hugging Face
  • PyTorch

About

Agentic Hybrid AI Debugging System with Intelligent Local Retrieval and Live Internet Reasoning

Topics

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors