Feat: AI-Inferred Schema Relationships and Multi-Collection Query Context#22
Merged
ChingEnLin merged 7 commits intodevfrom Feb 7, 2026
Merged
Feat: AI-Inferred Schema Relationships and Multi-Collection Query Context#22ChingEnLin merged 7 commits intodevfrom
ChingEnLin merged 7 commits intodevfrom
Conversation
…th cross-collection schema context.
…isualize collection relationships on the query generator page.
…ndling to pass a list of selected collections to the backend.
…rer buttons and add quick explore options for accounts.
|
🎉 This PR is included in version 2.7.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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 pull request introduces a significant new capability: AI-powered inference and visualization of schema relationships between MongoDB collections. It also enhances the natural language to query (NL2Query) feature by providing richer, multi-collection context to the AI model, improving its ability to generate complex queries involving relationships.
Key Features & Improvements:
AI-Powered Schema Relationship Inference:
SchemaRelationshipGraphcomponent visualizes these inferred relationships, showing source/target collections and fields, along with a confidence score and description. This helps users understand how collections might be connected.Enhanced Multi-Collection Context for NL2Query:
nl2queryendpoint has been updated to acceptaccount_idand a list ofcollection_contextobjects (representing multiple selected collections).Multi-Collection Selection in UI:
QueryGeneratorPagenow supports multi-selection of collections usingCtrl/Cmd+ click.Quick Data Explorer Launch:
Technical Details (Backend):
backend/models/schemas.py:QueryPromptschema modified to includeaccount_idand changecollection_contextto accept alist[CollectionContext].SchemaRelationshipsRequest,Relationship, andSchemaRelationshipsResponsefor structured relationship data.backend/routes/query.py:/query/infer-relationshipsadded, which acceptsSchemaRelationshipsRequest, performs OBO token exchange, fetches schema summaries for specific collections, and then calls the Gemini service to infer relationships.nl2queryendpoint now expectsaccount_idin theQueryPromptand uses the newget_database_schema_summaryto provide comprehensive schema context (all_collections_schema) to the Gemini model.backend/services/gemini_service.py:generate_schema_relationshipsimplemented to interact with the Gemini model for relationship inference, using a specific prompt template and structured output (PydanticSchemaRelationshipsResponse).generate_query_from_promptfunction now acceptsall_collections_schemaas a parameter to provide a broader database context to the AI.backend/services/mongo_service.py:get_database_schema_summaryintroduced, which connects to Cosmos DB, retrieves sample documents for specified (or all) collections, and generates a textual summary of the schema.Technical Details (Frontend):
frontend/types.ts:RelationshipandSchemaRelationshipsResponseadded to support relationship data.frontend/services/geminiService.ts:inferSchemaRelationshipsfunction added to make API calls to the new backend endpoint and handle authentication.generateMongoQueryfunction updated to includeaccountIdandselectedCollectionsparameters, aligning with the new backend schema. MSAL token acquisition logic is now part of these service calls.frontend/pages/QueryGeneratorPage.tsx:selectedCollections,collectionDetailsMap).inferSchemaRelationshipswhen multiple collections are selected, along with debouncing.handleLaunchExplorerandhandleQuickExploreAccountfor improved navigation to Data Explorer.CollectionActionPanelcards when multiple collections are selected.isExplorerNavEnabledprop fromHeaderUI.frontend/components/SchemaRelationshipGraph.tsx:This change significantly improves the QueryPal application by enabling more sophisticated AI-driven query generation and providing users with valuable insights into their database schema.