You could use an LLM to do some preprocessing on the query. Using like a pydantic program or something.
from typing import List
from pydanitc import BaseModel, Field
def Entity(BaseModel):
"""Represents an entity name (date, time, place, etc.) and it's associated value."""
name: str
value: str
def Entities(BaseModel):
"""A list of entities."""
entities: List[Entity]
from llama_index.program import OpenAIPydanticProgram
prompt = "Given a query, extract any useful entities. If none are found, return an empty list.\nQuery: {query_str}"
program = program = OpenAIPydanticProgram.from_defaults(
output_cls=Entities,
prompt_template_str=prompt,
llm=OpenAI(model="gpt-3.5-turbo-1106"),
)
entities = program(query_str="My query")
print(entities.entities)