liveBook · Manning

Query engine

As explained in Hugging Face in Action

A query engine is a software component that accepts a query and returns a response from an underlying data or knowledge source.

A query engine turns questions about indexed documents into generated responses. With LlamaIndex, configure it from an index and an LLM, then call query(). section 7.3.7

Querying local documents

A Hugging Face Llama model can run locally through HuggingFaceLLM. Select Apple Metal, CUDA, or CPU processing, then ask questions with query_engine.query(question).response. section 7.3.7

Choose the interaction pattern that matches the application:

  • Use query() for independent questions; it does not remember earlier turns. section 7.3.11
  • Use as_chat_engine() and chat() for follow-up questions that require conversation context. section 7.3.11
  • Bind the query function to Gradio to provide a browser-based text interface. section 7.3.10

A cloud OpenAI model such as gpt-4o-mini can improve speed and response quality, but requires an API key, incurs usage charges, and sends query context to OpenAI. section 7.3.9

How Hugging Face in Action covers it

How deep it goes
Explains configuration, device selection, interaction methods, and deployment trade-offs without detailing retrieval internals.
Examples
Uses PDF receipts, local Llama inference, OpenAI querying, Gradio interfaces, and follow-up purchase questions.
What it assumes
Assumes indexed documents and basic Python, while demonstrating model selection, device handling, and API setup.
What you can do after
Build it from scratch by configuring a LlamaIndex query engine and exposing it through Python or Gradio.
How it connects
Connects indexed documents, LlamaIndex, Hugging Face, OpenAI, LLMs, Gradio, and conversational memory.

Also explained in

Compare how 3 books explain query engine →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hugging Face in Action. The section links point to the parts of the book it draws on.