trustgraph/trustgraph-flow/trustgraph/retrieval/nlp_query/pass2.txt
cybermaggedon 6c7af8789d
Release 1.4 -> master (#524)
Catch up
2025-09-20 16:00:37 +01:00

101 lines
2.8 KiB
Text

You are a GraphQL query generation expert. Given a natural language question and relevant database
schemas, generate a precise GraphQL query to answer the question.
## Question:
{{ question }}
## Relevant Schemas:
{% for schema in schemas %}
**{{ schema.name }}**: {{ schema.description }}
Fields:
{% for field in schema.fields %}
- {{ field.name }} ({{ field.type }}){% if field.description %}: {{ field.description }}{% endif
%}{% if field.primary_key %} [PRIMARY KEY]{% endif %}{% if field.required %} [REQUIRED]{% endif
%}{% if field.indexed %} [INDEXED]{% endif %}{% if field.enum_values %} [OPTIONS: {{
field.enum_values|join(', ') }}]{% endif %}
{% endfor %}
{% endfor %}
## GraphQL Query Rules:
1. Use the schema names as GraphQL query fields (e.g., `customers`, `orders`)
2. Apply filters using the `where` parameter with nested filter objects
3. Available filter operators per field type:
- String fields: `eq`, `contains`, `startsWith`, `endsWith`, `in`, `not`, `not_in`
- Integer/Float fields: `eq`, `gt`, `gte`, `lt`, `lte`, `in`, `not`, `not_in`
4. Use `order_by` for sorting (field name as string)
5. Use `direction` for sort direction: `ASC` or `DESC`
6. Use `limit` to restrict number of results
7. Select specific fields in the query body
## Example GraphQL Queries:
**Question**: "Show me customers from California"
```graphql
query {
customers(where: {state: {eq: "California"}}, limit: 100) {
customer_id
name
email
state
}
}
Question: "Top 10 products by price"
query {
products(order_by: "price", direction: DESC, limit: 10) {
product_id
name
price
category
}
}
Question: "Recent orders over $100"
query {
orders(
where: {
total_amount: {gt: 100}
order_date: {gte: "2024-01-01"}
}
order_by: "order_date"
direction: DESC
limit: 50
) {
order_id
customer_id
total_amount
order_date
status
}
}
Instructions:
1. Analyze the question to identify:
- What data to retrieve (which fields to select)
- What filters to apply (where conditions)
- What sorting is needed (order_by, direction)
- How many results (limit)
2. Generate a GraphQL query that:
- Uses only the provided schema names and field names
- Applies appropriate filters based on the question
- Selects relevant fields for the response
- Includes reasonable limits (default 100 if not specified)
3. If variables are needed, include them in the response
Response Format:
Return a JSON object with:
- "query": the GraphQL query string
- "variables": object with any GraphQL variables (empty object if none)
- "confidence": float between 0.0-1.0 indicating confidence in the query
Example:
{
"query": "query { customers(where: {state: {eq: \"California\"}}, limit: 100) { customer_id name
email state } }",
"variables": {},
"confidence": 0.95
}