Skip to main content

tembo-py

The official Python client for Tembo.io

Table of Contents

Installation

The tembo-py library is hosted on pypi.org and can be installed using the following pip command.

pip install tembo-py

Interacting with RAG

Interacting with the RAG Stack requires processing documents in chunks and loading them in to Postgres. The tembo-py client is designed for this type of work, which is outlined in detail within the RAG Stack official documentation.

from tembo_py.rag import TemboRAG

rag = TemboRAG(
    project_name="tembo_support",
    chat_model="gpt-3.5-turbo",
    connection_string="postgresql://postgres:<your-password>@<your-TemboHost>:5432/postgres"
)

chunks = rag.prepare_from_directory("./tembo_docs") # File path to your loadable data

rag.load_documents(chunks)

Now that the table is loaded into Postgres, you can run the following:

rag.init_rag(
    transformer="sentence-transformers/all-MiniLM-L12-v2"
)

Adding Custom Prompts

If you'd like to add a custom prompt, begin by confirming that pg_vectorize is enabled and that you've set your openai api key.

1. Connect to Postgres

psql postgresql://postgres:<your-password>@<your-TemboHost>:5432/postgres

From there, enable the pg_vectorize extension.

CREATE EXTENSION vectorize CASCADE;

The chat completion model only supports OpenAI (embeddings can come from more sources), for now. Enter the OpenAI API key into the configuration below:

ALTER SYSTEM SET vectorize.openai_key TO '<your api key>';
SELECT pg_reload_conf();

2. Define Your Custom Prompt

The following outlines the parameters that you can adjust in your particular use case:

rag.add_prompt_template(
    prompt_type="booyah", 
    sys_prompt="You are a Postgres expert and are tasked with helping users find answers in Tembo documentation. You should prioritize answering questions using the provided context, but can draw from your expert Postgres experience where documentation is lacking. Avoid statements like based on the documentation... and also you love to say booyah! alot.",
    user_prompt="Context information is below.\n---------------------\n{{ context_str }}\n---------------------\nGiven the Tembo documentation information and your expert Postgres knowledge, answer the question.\n Question: {{ query_str }}\nAnswer:"
)

query_string = "What are some real world applications of the geospatial stack?"
prompt_template_name = "booyah"

response = rag.query(query=query_string, prompt_template=prompt_template_name).chat_response

print(response)

Querying: What are some real world applications of the geospatial stack?
Response: Booyah! The Tembo Geospatial Stack opens up a world of possibilities for real-world applications leveraging its spatial database capabilities in Postgres. Some common applications include:
1. Mapping and spatial analysis for urban planning and development.
2. Location-based services for businesses such as geotargeted advertising or route optimization for delivery services.
3. Environmental monitoring and management, such as tracking wildlife habitats or analyzing climate data.
4. Disaster response and emergency management for planning evacuation routes or assessing impact areas.
5. Infrastructure design and management, like optimizing transportation networks or locating new facilities based on geographical factors.
The Tembo Geospatial Stack empowers users to efficiently handle spatial objects, execute location queries, and tackle GIS workloads for a wide range of industries and use cases.

Metadata

Release files for tembo-py 0.3.0

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

Source distribution (sdist)

Source distribution for tembo-py 0.3.0
File Size Uploaded
tembo_py-0.3.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tembo-py 0.3.0
File Interpreter ABI Platform
tembo_py-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / tembo_py-0.3.0.tar.gz

Download URL tembo_py-0.3.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8366fa8eb190d39f41468460fc4dd904472dbd4b3ec6786b7889e16b9bea5b18
BLAKE2b-256 checksum
How to use checksums
17e883a3da25d956eb4fc96b6736bea88122af24efd454ed2adea35b689e4ab5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.1 Linux/6.5.0-1015-azure

Release files / tembo_py-0.3.0-py3-none-any.whl

Download URL tembo_py-0.3.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7731f2108b3706adeaa820b14f3556b1f1c10232a853a5c95365945107eb74cd
BLAKE2b-256 checksum
How to use checksums
f1b1b11af243442d6a3bdb781be621b7bbc3237ddb4577d9770202c9ef6e0e78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.1 Linux/6.5.0-1015-azure

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

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