Build applications using LlamaIndex

Preview — Spanner integration with LlamaIndex

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

You can build large language model (LLM) applications that use graphretrieval-augmented generation (GraphRAG) withLlamaIndex andSpanner Graph.

Spanner Graph integrates with LlamaIndex through itsproperty graph store capabilities to let you use the following to create dataretrieval workflows:

  • Property graph store: Lets you represent dataas a graph by storing nodes and edges in a graph database. You can use thegraph database to query for complex relationships in your data.

  • Graph retrievers: Lets you use an LLM to translatea user's natural language question into a query for the graph store.This enables applications to answer questions using the structuredrelationships in the graph data.

What is LlamaIndex?

LlamaIndex is a data framework for building LLM applications that helps youstreamline the development of retrieval-augmented generation (RAG) and othercontext-aware systems. By providing tools to connect LLMs with your data,LlamaIndex helps with data ingestion, indexing, and querying. You can useLlamaIndex with LLMs to build applications that deliver accurate andrelevant responses.

For more information about the LlamaIndex framework, see theLlamaIndex product documentation.

Property graph store for Spanner

A property graph store can be used in an application to do the following:

  • Extract entities and relationships from documents and store them as a graph.

  • Perform complex traversals and analysis on a graph structure.

  • Query a graph using the Graph Query Language (GQL) to provide specificcontext to an LLM.

To work with a property graph store in Spanner Graph, use theSpannerPropertyGraphStore class.

Property graph store tutorial

To learn how to use the property graph store with Spanner, seetheproperty graph store tutorial for Spanner.This tutorial helps you learn how to do the following:

  • Install thellama-index-spanner package and LlamaIndex

  • Initialize theSpannerPropertyGraphStore class and use it to connect toyour Spanner database.

  • Add nodes and edges to your Spanner Graph that contain data extractedfrom documents using a LlamaIndex knowledge graph extractor.

  • Retrieve structured information by querying the graph using GQL.

  • Visualize the results of your graph queries.

Graph retrievers for Spanner

Graph retrievers in LlamaIndex are components that use an LLM to translatea user's natural language question into a query for the graph store.Applications use the generated query to answer questions by using the structuredrelationships in the graph data. Graph retrievers use the following workflow togenerate an answer from a natural language query:

  1. Prompt an LLM to translate the natural language question into a GQL query.

  2. Run the GQL query against the graph store using Spanner Graph and theSpannerPropertyGraphStore class.

  3. Send the structured data that's returned by the query to the LLM usingSpanner Graph.

  4. Generate a human-readable answer using the LLM.

Use LlamaIndex retriever classes

The following LlamaIndex graph retriever classes can be used withSpanner Graph to generate human-readable answers to LLM prompts:

SpannerGraphTextToGQLRetriever class

TheSpannerGraphTextToGQLRetriever class translates natural language into GQLqueries for data extraction from the graph.

SpannerGraphCustomRetriever class

TheSpannerGraphCustomRetriever class implements a hybrid retrieval approach.SpannerGraphCustomRetriever handles specific and conceptual questions usingthe following steps:

  1. Perform the following searches simultaneously:

    • A graph search that translates the natural language question into a GQLquery that uses the graph to find answers.

    • A Vector Search or semantic search to find conceptually relatedinformation.

  2. Combine the results from the graph search and the vector search.

  3. Evaluate and re-rank the combined results using the LLM. The LLM selects themost relevant and context-aware information to answer the original question.

Graph retrievers tutorial

To learn how to use graph retrievers with Spanner to answerquestions, seethegraph retrievers tutorial for Spanner.This tutorial shows you how to:

  • Create a graph from unstructured text blobs.

  • Store the graph in Spanner using theSpannerPropertyGraphStore class

  • Initialize aSpannerGraphTextToGQLRetriever class and aSpannerGraphCustomRetriever instance using your graph store and an LLM.

  • Generate an answer to a natural language question using the graph datathat's stored in Spanner.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.