liveBook · Manning

Knowledge graph

As explained in Domain-Specific Small Language Models

A structured graph representation of entities and relationships used here to enrich RAG with explicit connections among concepts.

A knowledge graph represents entities, attributes, and relationships as connected structure. In retrieval-augmented generation, these explicit connections help expose context that semantic similarity may miss, especially for multihop questions spanning documents. section 14.1

A GraphRAG pipeline uses the graph operationally:

  • Extract entities and relationships from document chunks with an LLM, constraining the response to a Pydantic-defined JSON schema. section 14.1
  • Construct graphs from the extracted elements and combine them into a graph representing the document collection. section 14.1
  • Detect communities of closely connected entities, then generate summaries for those communities. section 14.1 section 14.4
  • Answer globally by generating partial responses from community summaries and combining them, or search locally by combining graph entities with document embeddings. section 14.1.1

Building a document knowledge graph

A Python workflow sends each text chunk to an Ollama model, requests entities and relationships in structured JSON, validates the result with Pydantic, and builds a NetworkX graph. It then applies Leiden community detection, summarizes each entity group, and combines community-level answers into a final response. section 14.1

Figure 14.1 The logical blocks and workflow of Microsoft’s GraphRAG proposal

The workflow diagram clarifies how indexing, entity graphs, community summaries, and query-time answer generation fit together. section 14.1

How Domain-Specific Small Language Models covers it

How deep it goes
Builds graphs through extraction, composition, Leiden community detection, summarization, and global or local search, while deferring alternative graph stores.
Examples
Uses document chunks, structured entity-and-relationship JSON, NetworkX graphs, community summaries, and combined intermediate answers.
What it assumes
Assumes familiarity with RAG and vector databases while introducing graph-based retrieval and community summarization.
What you can do after
Build and query a GraphRAG prototype with Ollama, Pydantic, NetworkX, Leiden community detection, and generated community summaries.
How it connects
Connects RAG with embeddings, vector databases, community detection, the Leiden algorithm, global search, and local search.

Also explained in

Compare how 12 books explain knowledge graph →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.