Skip to content

Add pluggable LLM backend and Layer 3 fallback for query optimization - #115

Open
sarthaksarthak9 wants to merge 4 commits into
BNLNPPS:mainfrom
sarthaksarthak9:feat/llm-integration
Open

Add pluggable LLM backend and Layer 3 fallback for query optimization#115
sarthaksarthak9 wants to merge 4 commits into
BNLNPPS:mainfrom
sarthaksarthak9:feat/llm-integration

Conversation

@sarthaksarthak9

Copy link
Copy Markdown

Description

This implements AI query optimization pipeline by introducing a pluggable LLM backend and integrating it as the final fallback layer for suggestion generation. It adds a BaseLLMBackend abstraction with implementations for Ollama, OpenAI, and a Mock backend for testing, allowing the backend to be selected through the CDB_LLM_BACKEND configuration.

An LLM analyzer has been added to build a schema-aware system prompt, invoke the configured backend, validate the returned response, and convert valid recommendations into Suggestion objects. All LLM-generated safe_sql statements go through the same allow-list validation as rule-engine suggestions before being persisted, ensuring they satisfy the existing safety guarantees.

The optimization collector has also been updated to follow a rules-first, LLM-as-fallback workflow. The LLM is only invoked for candidate queries that have already exceeded the latency or I/O thresholds and for which the rule engine produced no optimization suggestions. Suggestions generated by the LLM are assigned a default confidence score of 0.5, reflecting that they are intended to complement—not replace—the existing deterministic rule engine by covering optimization opportunities that are not recognized by the current set of rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant