The official Python client for Tembo.io
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tembo_py-0.3.0.tar.gz
.
File metadata
- Download URL: tembo_py-0.3.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.1 Linux/6.5.0-1015-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8366fa8eb190d39f41468460fc4dd904472dbd4b3ec6786b7889e16b9bea5b18 |
|
MD5 | fdf81a9c3da270100e98f52133a58371 |
|
BLAKE2b-256 | 17e883a3da25d956eb4fc96b6736bea88122af24efd454ed2adea35b689e4ab5 |
File details
Details for the file tembo_py-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: tembo_py-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.1 Linux/6.5.0-1015-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7731f2108b3706adeaa820b14f3556b1f1c10232a853a5c95365945107eb74cd |
|
MD5 | 1f6eb15d2ed11f1ac87213827777a222 |
|
BLAKE2b-256 | f1b1b11af243442d6a3bdb781be621b7bbc3237ddb4577d9770202c9ef6e0e78 |