Skip to main content

Spanner for LlamaIndex

preview pypi versions

Quick Start

In order to use this library, you first need to go through the following steps:

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Google Cloud Spanner API.
  4. Setup Authentication.

Installation

Install this library in a virtualenv using pip. virtualenv is a tool to create isolated Python environments. The basic problem it addresses is one of dependencies and versions, and indirectly permissions.

With virtualenv, it’s possible to install this library without needing system install permissions, and without clashing with the installed system dependencies.

Supported Python Versions

Python >= 3.9

Mac/Linux

pip install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install llama-index-spanner

Windows

pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install llama-index-spanner

Spanner Property Graph Store Usage

Use SpannerPropertyGraphStore to store nodes and edges extracted from documents.

from llama_index_spanner import SpannerPropertyGraphStore

graph_store = SpannerPropertyGraphStore(
    instance_id="my-instance",
    database_id="my-database",
    graph_name="my_graph",
)

See the full Spanner Graph Store tutorial.

Spanner Graph Retrievers Usage

Use SpannerGraphTextToGQLRetriever to translate natural language question to GQL and query SpannerPropertyGraphStore.

from llama_index_spanner import (
    SpannerPropertyGraphStore,
    SpannerGraphTextToGQLRetriever,
)
from llama_index.llms.google_genai import GoogleGenAI

graph_store = SpannerPropertyGraphStore(
    instance_id="my-instance",
    database_id="my-database",
    graph_name="my_graph",
)
llm = GoogleGenAI(
    model="gemini-2.0-flash",
)
retriever = SpannerGraphTextToGQLRetriever(graph_store=graph_store, llm=llm)
retriever.retrieve("Where does Elias Thorne's sibling live?")

Use SpannerGraphCustomRetriever to query your SpannerPropertyGraphStore with a hybrid retrieval approach, combining natural language-to-GQL translation with vector search capabilities.

The Vector Context Retriever uses semantic vector search to surface relevant contexts, even when they aren't explicitly structured in the graph. The Text2GQL Retriever translates natural language into GQL queries to extract precise relationships and attributes from the property graph.

The results from both retrievers are evaluated using an LLM-based reranker, which scores them based on relevance, completeness, and contextual fit with the original query.

This hybrid + rerank pipeline enables the system to handle everything from vague, open-ended questions to structured, entity-specific queries, delivering high-confidence, context-aware responses.

from llama_index_spanner import SpannerPropertyGraphStore, SpannerGraphCustomRetriever
from llama_index.llms.google_genai import GoogleGenAI
from llama_index.embeddings.google_genai import GoogleGenAIEmbedding

graph_store = SpannerPropertyGraphStore(
    instance_id="my-instance",
    database_id="my-database",
    graph_name="my_graph",
)
llm = GoogleGenAI(
    model="gemini-2.0-flash",
)
embed_model = GoogleGenAIEmbedding(model_name="text-embedding-004")
retriever = SpannerGraphCustomRetriever(
    similarity_top_k=4,
    path_depth=2,
    graph_store=graph_store,
    llm_text_to_gql=llm,
    embed_model=embed_model,
    llmranker_top_n=3,
)
retriever.retriever("Who lives in desert?")

See the full Spanner Graph Retrievers tutorial.

Contributing

Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information how to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Code of Conduct for more information.

License

Apache 2.0 - See LICENSE for more information.

Metadata

Release files for llama-index-spanner 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-spanner 0.1.5
File Size Uploaded
llama_index_spanner-0.1.5.tar.gz 53.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-spanner 0.1.5
File Interpreter ABI Platform
llama_index_spanner-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 93.4 kB

Release files / llama_index_spanner-0.1.5.tar.gz

Download URL llama_index_spanner-0.1.5.tar.gz
Size 53.9 kB
Tags Source
SHA-256 checksum
How to use checksums
177b2f7281eeb5503230ac19cbe73c875aa3d59ec0e3f29eeb7b8de8f7de9957
BLAKE2b-256 checksum
How to use checksums
97608e5f12c172d1a33539c63b7728d0ca5f1816c2b9ed28269314a599d9fab9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.11.2

Release files / llama_index_spanner-0.1.5-py3-none-any.whl

Download URL llama_index_spanner-0.1.5-py3-none-any.whl
Size 39.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
515c95e7ce66873c435ba49388c363530767ae33a2d6e7d98f4f4bf193c04f50
BLAKE2b-256 checksum
How to use checksums
6fff5e75b82693030493e04d7cb41322ab77c0131e19acb4306ec7337fc5cfea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page