Grit
  • Welcome
  • gritholdings SDK
    • API Reference
    • Collection of Useful Prompts
  • Evaluation
    • Evaluators
  • Concepts
  • LangChain
  • LangGraph
  • Agent Architectures
    • Planner-Worker-Solver
  • Prompt Management
  • Memory
  • Guardrails
  • Others
    • AWS
      • AWS CDK
    • Migrating a Service to Docker
    • React
    • Salesforce
      • Object Reference
      • Writing Apex
      • Experience Cloud
    • Grit API Reference
    • Style Guide for Documentation and User Interface Text
Powered by GitBook
On this page
  • Utils
  • Query Decomposition
  1. gritholdings SDK

API Reference

Previousgritholdings SDKNextCollection of Useful Prompts

Last updated 7 months ago

Utils

Query Decomposition

The QueryDecomposition class is used to decompose a complex question into multiple simpler questions using a LLM model. The class uses a default decomposition prompt from the . The default prompt is based on few-shot prompts from the StrategyQA dataset.

Initialize

To use the QueryDecomposition class, you first need to create an instance of the class.

from gritholdings.utils.query_decompose import QueryDecomposition

decomposer = QueryDecomposition()

Decompose

After the QueryDecomposition instance has been initialized, you can use the decompose method to decompose a query into multiple simpler questions. The decompose method takes a complex query as input and returns a list of simple queries.

query = "Is the customer's car still under warranty?"
decomposed_queries = decomposer.decompose(query)
print(decomposed_queries)
>>> ["When was the customer's vehicle purchased?", "What is the warranty period for the customer's vehicles?"]

If the input query is a simple question and doesn't require decomposition, the decompose method returns an empty list.

query = "What is your customer service phone number?"
decomposed_queries = decomposer.decompose(query)
print(len(decomposed_queries))
>>> 0
Visconde paper