It seems like just yesterday we released Select AI for Python, and since then we’ve added a flood of new features for Select AI and Select AI Agent on Oracle Autonomous AI Database. Now we’re announcing Select AI for Python v1.2, which adds these same new features for Python users of Select AI: functionality for AI agents, text summarization, NL2SQL feedback, proxy object creation and modification, as well as additional control over granting and revoking privileges and HTTP access. In addition, Select AI for Python now supports Python 3.14.
What is Select AI for Python?
Select AI for Python enables you to ask questions about your database data using natural language (text-to-SQL), receive generative AI responses using your trusted content (retrieval-augmented generation), generate synthetic data using large language models, and more – all from Python. With Select AI for Python, you can leverage the broader Python ecosystem in combination with Oracle’s database functionality and generative AI capabilities – bridging the gap between the Select AI’s DBMS_CLOUD_AI PL/SQL package and Python’s rich ecosystem. It provides intuitive objects and methods for Pythonic AI model interaction.
With Select AI, there is no model vendor lock-in. You can choose your favorite LLMs and transformers from a wide range of AI providers, like OpenAI, Anthropic, AWS, Cohere, and others. You can even work with AI models from private endpoints to keep your models, data, and metadata under your control for added security. Of course, you benefit from the same Oracle enterprise-grade database security and availability.
You can use the Python API to create AI profile objects for NL2SQL or RAG, or define AI Agents. Alternatively, you can also use the Ask Oracle chatbot for no-code interaction with your database for NL2SQL, RAG, and agents. This makes it easy to use – as well as evaluate/test – your solutions.
Summary of new features
Select AI for Python v1.2.0 includes the following new features:
AI Agents – build, run, and manage AI agents from your database
- select_ai.agent.Tool
- select_ai.agent.Task
- select_ai.agent.Agent
- select_ai.agent.Team
Summarize – easily summarize text content
- ai_profile.summarize()
NL2SQL Feedback – provide feedback on query results and the generated queries themselves to help improve query results
- ai_profile.add_positive_feedback()
- ai_profile.add_negative_feedback()
- ai_profile.delete_feedback()
Fetch API – create a proxy object from the name of a given object
- Profile.fetch(profile_name)
- Conversation.fetch(conversation_id)
- Agent.fetch(agent_name)
- Tool.fetch(tool_name)
- Task.fetch(task_name)
- Team.fetch(team_name)
Proxy objects have set_attribute and set_attributes() methods
- set_attribute(attribute_name, attribute_value) accepts a single attribute
- set_attributes(attributes) accepts multiple attributes using the applicable attributes class
Granting/revoking privileges and access
- select_ai.grant_privileges
- select_ai.revoke_privileges
- select_ai.grant_http_access
- select_ai.revoke_http_access
DBMS_CLOUD_AI_AGENT is added to the list of packages requiring ‘execute’ privilege
- ‘DBMS_CLOUD’,
- ‘DBMS_CLOUD_AI’,
- ‘DBMS_CLOUD_AI_AGENT’,
- ‘DBMS_CLOUD_PIPELINE’
Example using Select AI for Python
The following code example illustrates how to use Select AI for Python.
First, we import the select_ai module and connect to our database instance using the connect method and our credentials. Once we’re connected, we create a provider object, which in our example is OCI GenAI in the Chicago region. We create a profile attributes object to specify the credential name, the object list (which indicates that we want to use all tables from the SH schema), and our provider object. We use these as input to create an AI profile, where we provide a profile name oci_ai_profile, our profile attributes, a description, and an instruction that allows us to replace any existing profile with the same name.
import os
import select_ai
user = os.getenv(“SELECT_AI_USER”)
password = os.getenv(“SELECT_AI_PASSWORD”)
dsn = os.getenv(“SELECT_AI_DB_CONNECT_STRING”)
select_ai.connect(user=user, password=password, dsn=dsn)
provider = select_ai.OCIGenAIProvider(region = “us-chicago-1”,
oci_apiformat = “GENERIC”)
profile_attributes = select_ai.ProfileAttributes(provider = provider ,
credential_name = “my_oci_ai_profile_key”,
object_list = [{“owner”: “SH”}])
profile = select_ai.Profile(profile_name = “oci_ai_profile”,
attributes = profile_attributes,
description = “MY OCI AI Profile for accessing SH tables and views”,
replace = True)
Now, we’re ready to use Select AI for Python to generate a SQL query from our natural language prompt using the show_sql method.
sql = profile.show_sql(prompt = “What are customer sales by product?”)
print(sql)
Output:
SELECT
p.”PROD_NAME” AS “Product Name”,
SUM(s.”AMOUNT_SOLD”) AS “Total Sales”
FROM
“SH”.”SALES” s
JOIN “SH”.”PRODUCTS” p ON s.”PROD_ID” = p.”PROD_ID”
GROUP BY
p.”PROD_NAME”
Using the method run_sql, Select AI for Python also runs the query and returns the result of that query in a DataFrame object.
df = profile.run_sql(prompt = “What are customer sales last year by product and region?”)
print(df.columns)
print(df)
Output:
Index([‘Product Name’, ‘Total Sales’], dtype=’object’)
Product Name Total Sales
0 5MP Telephoto Digital Camera 6312268.4
1 17″ LCD w/built-in HDTV Tuner 7189171.77
…
Using one of the newer capabilities for text summarization, we invoke summarize with the text in our content string.
Content = “””
A gas cloud in our galaxy, Sagittarius B2, contains enough alcohol to brew 400
trillion pints of beer, and some stars are so cool that you could touch them
without being burned. Meanwhile, on the exoplanet 55 Cancri e, a form of
“hot ice” exists where high pressure prevents water from becoming gas even at
high temperatures. Additionally, some ancient stars found in the Milky Way’s
halo are much older than the Sun, providing clues about the early universe and
its composition. …
“””
summary = profile.summarize(content=content)
print(summary)
Output:
A gas cloud in the Sagittarius B2 galaxy contains a large amount of alcohol,
while some stars are cool enough…
Resources
Try Select AI for Python by installing select_ai from our GitHub repository or PyPI. Refer to the resources below for more information:
- Select AI for Python
