Fix API contract bugs and refactor Model to persist knowledge base state across requests - #506
Open
happy4pizza wants to merge 7 commits into
Open
happy4pizza wants to merge 7 commits into
happy4pizza wants to merge 7 commits into
Conversation
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes several bugs introduced during the MLflow 2.x to 3.x migration and completes an architectural refactor to make the pipeline functional end to end.
Bug Fixes
update_kbcommand not being handled inpredict()- the model was treating it as a search query, running the full RAG pipeline against it, and returning a response with nostatuskey, sokb_readynever flipped toTruein the UIforce_regenerateas a top-level column which violated the MLflow schema (queryandpayloadrequired). All query data now lives inside thepayloadJSON fieldKeyError: 'config'on every chat query - the query path was calling_build_transient_kb()which expectedpayload["config"]andpayload["secrets"], but chat payloads only contain the questionTypeErrorwhen displaying metrics - added a None guard before formatting generation time, faithfulness, and relevance so the UI doesn't crash if any metric is missingmain.py-loggerwas referenced before being definedArchitectural Refactor
_initialize_kb()which builds the KB (knowledge base) once onupdate_kband stores all state (bm25_index,doc_map,rag_pipeline) on theModelinstance_build_transient_kb()from the query path entirely - regular queries now callself.rag_pipeline.generate()directly against the already-built KB_initialize_kb()to pre-compile Triton CUDA kernels so the first real user query returns in seconds rather than minutesdatafabricpath on startup. If not found, it downloads automatically from the Hugging Face Hub before proceeding.image_filesto the API response - the model now returns the original image filenames (e.g.image-68e01678-....png) alongside the existing base64 blobs in a newimage_filesfield. This enables external evaluation tooling to validate image retrieval against expected sources without requiring direct access to the internal vector store, and unblocks image hit rate, precision, and recall metrics in the evaluation harnessDocumentation
README.mdto reflect the current AI Studio deployment workflow, including corrected setup steps, and hardware requirements aligned with the actual CUDA version in useResult
Query latency drops from 3+ minutes (due to wiki cloning, re-embedding, and Triton JIT compilation on every request) to seconds. The KB rebuilds only when the user explicitly clicks "Sync", and Triton kernels are pre-compiled during sync so the first real query is fast approx. 10 seconds on testing.