Spanner for LlamaIndex
Quick Start
In order to use this library, you first need to go through the following steps:
- Select or create a Cloud Platform project.
- Enable billing for your project.
- Enable the Google Cloud Spanner API.
- 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.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llama_index_spanner-0.1.6.tar.gz | 55.6 kB | With provenance | Details for llama_index_spanner-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llama_index_spanner-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for llama_index_spanner-0.1.6-py3-none-any.whl |
Total release size: 95.1 kB
Release files / llama_index_spanner-0.1.6.tar.gz
| Download URL | llama_index_spanner-0.1.6.tar.gz |
|---|---|
| Size | 55.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a724587fdddce8cc3507d509aa8b590b7b2a6ac8e4026a4b9114906d83de23f4
|
|
BLAKE2b-256 checksum How to use checksums |
17e4b75361034c9203d23f8073f8fb45c4f7d4f9e02ed8d87b9c46512ba9c1bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by Google Cloud, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / llama_index_spanner-0.1.6-py3-none-any.whl
| Download URL | llama_index_spanner-0.1.6-py3-none-any.whl |
|---|---|
| Size | 39.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4b465ddf38ae9faa9148f2cd90e9d4d97a3b1ef8431ee1ed89b189942162580
|
|
BLAKE2b-256 checksum How to use checksums |
cc61a76b2a291a2bc2f47395b6db1f2cdfe87acf195b953fce0c19e89d8fd0a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by Google Cloud, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for llama-index-spanner 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for llama_index_spanner-0.1.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by Google Cloud, verified by PyPI on Nov 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.