liveBook · Manning

Chapter 14: Asking a KG questions with natural language

What you will learn in chapter 14 of Knowledge Graphs and LLMs in Action

The chapter introduces an expert-emulated approach to asking knowledge graphs questions and explains why its design accounts for presenting answers to end users.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces an expert-emulated approach to asking knowledge graphs questions and explains why its design accounts for presenting answers to end users.

Key terms: front-end layer, integration-first approach, query responses, data visualization

14.1 Querying a knowledge graph in the policing domain

The section explains why policing agencies need a knowledge graph to bring together data generated across investigations and roles.

Key terms: KG, single source of truth, roles, processes, and data

14.1.1 Enabling domain experts with knowledge graphs

This section explains why giving policing analysts direct, intuitive access to knowledge graphs makes better use of their expertise and removes technical bottlenecks.

Key terms: domain expert, contextual knowledge, KGs, technical barriers, direct access

14.2 RAG for KG querying: Capabilities and challenges

The section explains why law enforcement experts need answers grounded in organizational data rather than generic LLM responses, while flagging incomplete retrieval as a limitation of RAG.

Key terms: LLMs, training phase, RAG, data available to an organization, incomplete retrieval, context

14.2.1 RAG effectiveness with complete context

The section shows how an LLM can answer case questions using retrieved witness statements and why broader questions require relevant context from additional sources.

Key terms: RAG, context, witness statements, left-handed, relevant pieces of information, retrieval, filtering, contextual augmentation

14.2.2 RAG fragility with incomplete retrieval

This section shows how incomplete retrieval can make a RAG system give a confident but incorrect answer, especially when evidence is spread across documents.

Key terms: RAG, retrieval process, incomplete context, passages, granularity, relevance, fragmented context

14.3 Schema-based approach for querying KGs

The section contrasts the limits of RAG-like context selection with an expert’s use of a graph schema to turn a natural-language question into a precise query.

Key terms: RAG-like approach, context, domain experts, schema, nodes, relationships, traversal, constraints, formal queries

14.3.1 Understanding and using graph schemas

Explains how knowledge of a graph schema turns a natural-language question into constrained traversals that can be composed into executable queries.

Key terms: graph schema, nodes, properties, relationships, constraints, constrained traversals, aggregations, structured queries

14.4 Think like an expert: Using metadata for enhanced querying

The section explains how an LLM can use a knowledge graph’s schema to formulate questions as precise queries rather than generate answers from retrieved context.

Key terms: expert reasoning, schema, entities, relationships, contextually appropriate queries, traditional RAG, formal queries, factual retrieval, KG

14.5 Intent detection: Understanding user expectations

This section explains why the question-answering system detects a user’s intent first: to choose a suitable presentation and processing path.

Key terms: Intent detection module, user’s intent, pipeline or chain, expert reasoning, semantic understanding, classification step

14.5.1 Classifying by visualization type

This section shows how to classify a knowledge-graph question by the visualization the user wants and how to refine that classification prompt when requests are ambiguous.

Key terms: intent detection, graph, table, chart, map, classification prompt, task definition, few-shots section, JSON, reason field

14.5.2 Is it data, documentation, or just complaining?

This section broadens intent detection beyond KG data queries and explains how to design and assess prompts that route varied user requests.

Key terms: data-related questions, system-related questions, feedback and complaints, documentation-related questions, schema-related questions, task definition, few-shot section, reason field, boundary cases, expected output format

14.6 From schema to LLM-ready context

This section introduces schema extraction and expert-oriented metadata enrichment as ways to make a knowledge graph schema usable by LLMs.

Key terms: schema extraction, metadata, enrichments, LLM-compatible formats

14.6.1 Schema extraction and representation

The section explains how to turn a technical Neo4j schema into a focused, structured conceptual schema that an LLM can use to generate Cypher queries.

Key terms: apoc.meta.schema, technical database schema, conceptual KG schema, domain experts, cognitive load, query errors, skip list, narrative schema representation, LLM-friendly format, structured representation

14.6.2 Enriching schemas with descriptive annotations

This section explains why an LLM needs descriptive schema annotations, not just graph structure, to translate natural-language questions into accurate KG queries.

Key terms: schema structure, BLK, COMMITTED, CO_OFFENDS_WITH, annotated schema, descriptive annotations, inline comments, cheat sheet

14.6.3 A practical approach to schema representation

This subsection presents a YAML configuration for turning KG schema output into a focused, annotated representation that an LLM can interpret.

Key terms: YAML configuration file, apoc.meta.schema, skip, descriptions, core conceptual KG schema, Customization, Maintainability, Scalability, YAML file

14.7 It’s time to think: Understanding LLM reasoning

The section places Cypher query generation within the question-answering workflow and explains why prompts can encourage an LLM to work through complex questions before answering.

Key terms: query generation, processed user intent, schema data, execution error feedback, Cypher queries, chain-of-thought prompting, scratchpad techniques, intermediate steps, time to think

14.7.1 The order matters: Answer first vs. reasoning first

This section explains how the order of an LLM’s answer and reasoning affects its output, and why classification tasks can warrant a different order.

Key terms: semantic consistency, cumulative context, error propagation, step-by-step reasoning, final answer, classification tasks, misclassifies, classification boundaries

14.7.2 Thinking in queries: From text to Cypher

This section builds a structured prompt that turns natural-language questions into schema-compliant Cypher queries and returns the result in a machine-readable format.

Key terms: Cypher, Graph Schema, annotations, examples, labels, relationships, intent detection, output_type, graph, map

14.7.3 Structuring output for reliable query generation

The section explains how ordering a model’s output fields and keeping examples consistent can make generated Cypher queries more reliable.

Key terms: relationships, reasoning field, Cypher query, schema description, response format, "..." notation, examples

14.8 Response summarization: From results to insights

This section explains how the final summarization step turns graph query results into a focused textual answer that complements the visual graph.

Key terms: summarization step, graph visualization, node properties, original question, executed Cypher query, query results, current selection, complete paths, results_analysis, reasoning

14.9 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 13: Knowledge graph–powered retrieval-augmented generation Chapter 15: Building a QA agent with LangGraph →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.