Skip to main content

LlamaIndex integrations for Google Cloud SQL for PostgreSQL

Project description

preview pypi versions

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:

  1. Select or create a Cloud Platform project.

  2. Enable billing for your project.

  3. Enable the Cloud SQL Admin 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-cloud-sql-pg

Windows

pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install llama-index-cloud-sql-pg

Example Usage

Code samples and snippets live in the samples/ folder.

Vector Store Usage

Use a vector store to store embedded data and perform vector search.

import google.auth
from llama_index.core import Settings
from llama_index.embeddings.vertex import VertexTextEmbedding
from llama_index_cloud_sql_pg import PostgresEngine, PostgresVectorStore


credentials, project_id = google.auth.default()
engine = await PostgresEngine.afrom_instance(
   "project-id", "region", "my-instance", "my-database"
)
Settings.embed_model = VertexTextEmbedding(
   model_name="textembedding-gecko@003",
   project="project-id",
   credentials=credentials,
)

vector_store = await PostgresVectorStore.create(
   engine=engine, table_name="vector_store"
)

Chat Store Usage

A chat store serves as a centralized interface to store your chat history.

from llama_index.core.memory import ChatMemoryBuffer
from llama_index_cloud_sql_pg import PostgresChatStore, PostgresEngine


engine = await PostgresEngine.afrom_instance(
   "project-id", "region", "my-instance", "my-database"
)
chat_store = await PostgresChatStore.create(
   engine=engine, table_name="chat_store"
)
memory = ChatMemoryBuffer.from_defaults(
   token_limit=3000,
   chat_store=chat_store,
   chat_store_key="user1",
)

Document Reader Usage

A Reader ingest data from different data sources and data formats into a simple Document representation.

from llama_index.core.memory import ChatMemoryBuffer
from llama_index_cloud_sql_pg import PostgresReader, PostgresEngine


engine = await PostgresEngine.afrom_instance(
   "project-id", "region", "my-instance", "my-database"
)
reader = await PostgresReader.create(
   engine=engine, table_name="my-db-table"
)
documents = reader.load_data()

Document Store Usage

Use a document store to make storage and maintenance of data easier.

from llama_index_cloud_sql_pg import PostgresEngine, PostgresDocumentStore


engine = await PostgresEngine.afrom_instance(
   "project-id", "region", "my-instance", "my-database"
)
doc_store = await PostgresDocumentStore.create(
   engine=engine, table_name="doc_store"
)

Index Store Usage

Use an index store to keep track of indexes built on documents.

from llama_index_cloud_sql_pg import PostgresIndexStore, PostgresEngine


engine = await PostgresEngine.from_instance(
   "project-id", "region", "my-instance", "my-database"
)
index_store = await PostgresIndexStore.create(
   engine=engine, table_name="index_store"
)

Contributions

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.

Disclaimer

This is not an officially supported Google product.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_cloud_sql_pg-0.2.3.tar.gz (59.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_cloud_sql_pg-0.2.3-py3-none-any.whl (50.7 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_cloud_sql_pg-0.2.3.tar.gz.

File metadata

  • Download URL: llama_index_cloud_sql_pg-0.2.3.tar.gz
  • Upload date:
  • Size: 59.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for llama_index_cloud_sql_pg-0.2.3.tar.gz
Algorithm Hash digest
SHA256 362359f2ae2407fcb1d1081aad034aa0c35926ee62959c8f6c1ebde04f141164
MD5 da829ef40b5df4b0733d757dd20ac400
BLAKE2b-256 7a0050f4a5f14436ccf01166cad69485bb35d2a90d8028131b6a7fd9ce932b0e

See more details on using hashes here.

File details

Details for the file llama_index_cloud_sql_pg-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_cloud_sql_pg-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 28d20a3b7df09164615f46ca627fceb0a82f130124c3582c8db863ec868dae4f
MD5 164655385ba8a337d40131951b6aa7e3
BLAKE2b-256 482ce1426e113a8c0bb25b9194957d9d83ebdc93841f1e53da6a72c6f61a1793

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page