The Cloud SQL for PostgreSQL for LlamaIndex package provides a first class experience for connecting to
Cloud SQL instances from the LlamaIndex ecosystem while providing the following benefits:
Simplified & Secure Connections: easily and securely create shared connection pools to connect to Google Cloud databases utilizing IAM for authorization and database authentication without needing to manage SSL certificates, configure firewall rules, or enable authorized networks.
Improved metadata handling: store metadata in columns instead of JSON, resulting in significant performance improvements.
Clear separation: clearly separate table and extension creation, allowing for distinct permissions and streamlined workflows.
Quick Start
In order to use this library, you first need to go through the following
steps:
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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [0.2.3 (latest)](/python/docs/reference/llama-index-cloud-sql-pg/latest)\n- [0.2.2](/python/docs/reference/llama-index-cloud-sql-pg/0.2.2) \n\nCloud SQL for PostgreSQL for LlamaIndex\n=======================================\n\n[](https://github.com/googleapis/google-cloud-python/blob/main/README.rst#stability-levels) [](https://pypi.org/project/llama-index-cloud-sql-pg/) [](https://pypi.org/project/llama-index-cloud-sql-pg/)\n\n- [Client Library Documentation](https://cloud.google.com/python/docs/reference/llama-index-cloud-sql-pg/latest)\n\n- [Product Documentation](https://cloud.google.com/sql/docs)\n\nThe **Cloud SQL for PostgreSQL for LlamaIndex** package provides a first class experience for connecting to\nCloud SQL instances from the LlamaIndex ecosystem while providing the following benefits:\n\n- **Simplified \\& Secure Connections**: easily and securely create shared connection pools to connect to Google Cloud databases utilizing IAM for authorization and database authentication without needing to manage SSL certificates, configure firewall rules, or enable authorized networks.\n\n- **Improved metadata handling**: store metadata in columns instead of JSON, resulting in significant performance improvements.\n\n- **Clear separation**: clearly separate table and extension creation, allowing for distinct permissions and streamlined workflows.\n\nQuick Start\n-----------\n\nIn order to use this library, you first need to go through the following\nsteps:\n\n1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)\n\n2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)\n\n3. [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin.googleapis.com)\n\n4. [Setup Authentication.](https://googleapis.dev/python/google-api-core/latest/auth.html)\n\n### Installation\n\nInstall this library in a [virtualenv](https://virtualenv.pypa.io/en/latest/) using pip. [virtualenv](https://virtualenv.pypa.io/en/latest/) is a tool to create isolated Python environments. The basic problem it addresses is\none of dependencies and versions, and indirectly permissions.\n\nWith [virtualenv](https://virtualenv.pypa.io/en/latest/), it's\npossible to install this library without needing system install\npermissions, and without clashing with the installed system\ndependencies.\n\n#### Supported Python Versions\n\nPython \\\u003e= 3.9\n\n#### Mac/Linux\n\n pip install virtualenv\n virtualenv \u003cyour-env\u003e\n source \u003cyour-env\u003e/bin/activate\n \u003cyour-env\u003e/bin/pip install llama-index-cloud-sql-pg\n\n#### Windows\n\n pip install virtualenv\n virtualenv \u003cyour-env\u003e\n \u003cyour-env\u003e\\Scripts\\activate\n \u003cyour-env\u003e\\Scripts\\pip.exe install llama-index-cloud-sql-pg\n\nExample Usage\n-------------\n\nCode samples and snippets live in the [samples/](https://github.com/googleapis/llama-index-cloud-sql-pg-python/tree/main/samples) folder.\n\n### Vector Store Usage\n\nUse a vector store to store embedded data and perform vector search. \n\n import google.auth\n from llama_index.core import Settings\n from llama_index.embeddings.vertex import VertexTextEmbedding\n from llama_index_cloud_sql_pg import PostgresEngine, PostgresVectorStore\n\n\n credentials, project_id = google.auth.default()\n engine = await PostgresEngine.afrom_instance(\n \"project-id\", \"region\", \"my-instance\", \"my-database\"\n )\n Settings.embed_model = VertexTextEmbedding(\n model_name=\"textembedding-gecko@003\",\n project=\"project-id\",\n credentials=credentials,\n )\n\n vector_store = await PostgresVectorStore.create(\n engine=engine, table_name=\"vector_store\"\n )\n\n### Chat Store Usage\n\nA chat store serves as a centralized interface to store your chat history. \n\n from llama_index.core.memory import ChatMemoryBuffer\n from llama_index_cloud_sql_pg import PostgresChatStore, PostgresEngine\n\n\n engine = await PostgresEngine.afrom_instance(\n \"project-id\", \"region\", \"my-instance\", \"my-database\"\n )\n chat_store = await PostgresChatStore.create(\n engine=engine, table_name=\"chat_store\"\n )\n memory = ChatMemoryBuffer.from_defaults(\n token_limit=3000,\n chat_store=chat_store,\n chat_store_key=\"user1\",\n )\n\n### Document Reader Usage\n\nA Reader ingest data from different data sources and data formats into a simple Document representation. \n\n from llama_index.core.memory import ChatMemoryBuffer\n from llama_index_cloud_sql_pg import PostgresReader, PostgresEngine\n\n\n engine = await PostgresEngine.afrom_instance(\n \"project-id\", \"region\", \"my-instance\", \"my-database\"\n )\n reader = await PostgresReader.create(\n engine=engine, table_name=\"my-db-table\"\n )\n documents = reader.load_data()\n\n### Document Store Usage\n\nUse a document store to make storage and maintenance of data easier. \n\n from llama_index_cloud_sql_pg import PostgresEngine, PostgresDocumentStore\n\n\n engine = await PostgresEngine.afrom_instance(\n \"project-id\", \"region\", \"my-instance\", \"my-database\"\n )\n doc_store = await PostgresDocumentStore.create(\n engine=engine, table_name=\"doc_store\"\n )\n\n### Index Store Usage\n\nUse an index store to keep track of indexes built on documents. \n\n from llama_index_cloud_sql_pg import PostgresIndexStore, PostgresEngine\n\n\n engine = await PostgresEngine.from_instance(\n \"project-id\", \"region\", \"my-instance\", \"my-database\"\n )\n index_store = await PostgresIndexStore.create(\n engine=engine, table_name=\"index_store\"\n )\n\n### Contributions\n\nContributions to this library are always welcome and highly encouraged.\n\nSee [CONTRIBUTING](https://github.com/googleapis/llama-index-cloud-sql-pg-python/tree/main/CONTRIBUTING.md) for more information how to get started.\n\nPlease note that this project is released with a Contributor Code of Conduct. By participating in\nthis project you agree to abide by its terms. See [Code of Conduct](https://github.com/googleapis/llama-index-cloud-sql-pg-python/tree/main/CODE_OF_CONDUCT.md) for more\ninformation.\n\nLicense\n-------\n\nApache 2.0 - See\n[LICENSE](https://github.com/googleapis/llama-index-cloud-sql-pg-python/tree/main/LICENSE)\nfor more information.\n\nDisclaimer\n----------\n\nThis is not an officially supported Google product."]]