From a015ded81e19e84693b724ab442a77a3fce29ca2 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Thu, 4 Sep 2025 13:29:47 +0100 Subject: [PATCH] Send structured data to prompt --- .../trustgraph/retrieval/nlp_query/pass1.txt | 32 +++++++++++++++++++ .../trustgraph/retrieval/nlp_query/service.py | 4 +-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 trustgraph-flow/trustgraph/retrieval/nlp_query/pass1.txt diff --git a/trustgraph-flow/trustgraph/retrieval/nlp_query/pass1.txt b/trustgraph-flow/trustgraph/retrieval/nlp_query/pass1.txt new file mode 100644 index 00000000..698aaa9c --- /dev/null +++ b/trustgraph-flow/trustgraph/retrieval/nlp_query/pass1.txt @@ -0,0 +1,32 @@ +You are a database schema selection expert. Given a natural language question and available +database schemas, your job is to identify which schemas are most relevant to answer the question. + +## Available Schemas: +{{schemas}} + +## Question: +{{question}} + +## Instructions: +1. Analyze the question to understand what data is being requested +2. Examine each schema to understand what data it contains +3. Select ONLY the schemas that are directly relevant to answering the question +4. Return your answer as a JSON array of schema names (just the names, not full objects) + +## Selection Criteria: +- Include schemas that contain data directly needed to answer the question +- Include schemas that contain fields referenced in the question +- Do NOT include schemas just because they might be tangentially related +- Prefer fewer, more relevant schemas over many loosely related ones +- If the question mentions specific entities, look for schemas containing those entities + +## Examples: +- Question: "Show me customers from California" → Schemas with customer data and location fields +- Question: "What are our top selling products last month?" → Schemas with product data and +sales/order data +- Question: "Which employees work in engineering?" → Schemas with employee data and +department/role information + +## Response Format: +Return ONLY a JSON array of schema names, nothing else. +Example: ["customers", "orders", "products"] diff --git a/trustgraph-flow/trustgraph/retrieval/nlp_query/service.py b/trustgraph-flow/trustgraph/retrieval/nlp_query/service.py index fa3f845b..1e962e0a 100644 --- a/trustgraph-flow/trustgraph/retrieval/nlp_query/service.py +++ b/trustgraph-flow/trustgraph/retrieval/nlp_query/service.py @@ -142,7 +142,7 @@ class Processor(FlowProcessor): # Create prompt variables variables = { "question": question, - "schemas": json.dumps(schema_info, indent=2) + "schemas": schema_info # Pass structured data directly } # Call prompt service for schema selection @@ -198,7 +198,7 @@ class Processor(FlowProcessor): # Create prompt variables for GraphQL generation variables = { "question": question, - "schemas": json.dumps(selected_schema_info, indent=2) + "schemas": selected_schema_info # Pass structured data directly } # Call prompt service for GraphQL generation