AI Q&A: Repo-Aware Chat with 3-Tier Fallback

By (author)Maheen Iftikhar

Tech stack:
PY

CodeMesh-AIs AI chat endpoint: searches indexed files for context, then tries OpenAI, local Ollama, then a heuristic fallback — so it always answers, ...
read more
AI Contributions:2
Published At:August 13, 2026
Files Included:1 file(s)
Updated At:October 23, 2026

Read Me

# AI Q&A Endpoint — CodeMesh-AI

## What it does
POST /api/ai/chat lets a developer ask natural-language questions
about a repository. It doesn't just forward the question to an LLM —
it first builds real context from the indexed codebase.

## How context is built
1. Keyword-searches indexed files by path, module, and function names
2. Pulls each matched file's pre-generated summary (if any)
3. Lists that file's classes and functions
4. Appends a repo-level summary as closing context

## 3-tier answer fallback
1. OpenAI-compatible API, if AI_API_KEY is set
2. Local Ollama (qwen2.5-coder), if reachable
3. Deterministic heuristic: lists the most relevant files found,
   so the endpoint never returns nothing — even with zero AI
   providers configured

## Response
Returns the answer plus which files were used as context and
which provider answered (openai / ollama / heuristic) — full
transparency, no black box.

## Files
backend/app/api/ai.py
backend/app/schemas/ai.py

## Verified in repo
Commit a1662c6 — Add code-index, AI Q&A, and repo services

Loading

Loading

Loading

More like this View all

ML Audit — SHAP Explainability Module

A plug-and-play Python script for auditing machine learning models using SHAP (SHapley Additive exPlanations). Produces client-ready charts, ranked importance tables, and flagged predictions suitable

  • 0

    Ratings

  • 1

    Files

    • PY

    Tech stack

Structured Generative AI Workout Architect

A robust Python module that uses Google's Gemini to generate highly personalized workout plans while strictly adhering to a predefined exercise library. It uses structured JSON schemas, advanced promp

  • 0

    Ratings

  • 1

    Files

    • PY

    Tech stack

gig-claude-developer-security-report

Turns deterministic security-scan findings into a plain-English developer report using live Claude — the AI writes the narrative, never the severity or facts.

  • 0

    Ratings

  • 4

    Files

    • PY

    Tech stack