Skip to content

Commit 27846fc

Browse files
authored
Merge pull request #8 from oracle/dev/v1.1.0
v1.1.0
2 parents fe8a14f + db9a904 commit 27846fc

11 files changed

+399
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ doc/build
1111
doc/drawio
1212
**/__pycache__
1313
test.env
14+
test_19c.env

doc/source/user_guide/vector_index.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,42 @@ output::
8181

8282
.. latex:clearpage::
8383
84+
85+
Get vector index attributes
86+
+++++++++++++++++++++++++++
87+
88+
You can fetch the vector index attributes and associated AI profile using
89+
``vector_index.get_attributes()`` and ``vector_index.get_profile()`` methods
90+
respectively.
91+
92+
.. literalinclude:: ../../../samples/vector_index_get_attributes.py
93+
:language: python
94+
:lines: 14-
95+
96+
output::
97+
98+
OracleVectorIndexAttributes(chunk_size=1024, chunk_overlap=128, location='https://objectstorage.us-ashburn-1.oraclecloud.com/n/dwcsdev/b/conda-environment/o/tenant1-pdb3/graph', match_limit=5, object_storage_credential_name='my_oci_ai_profile_key', profile_name='oci_vector_ai_profile', refresh_rate=1450, similarity_threshold=0.5, vector_distance_metric='COSINE', vector_db_endpoint=None, vector_db_credential_name=None, vector_db_provider=<VectorDBProvider.ORACLE: 'oracle'>, vector_dimension=None, vector_table_name=None, pipeline_name='TEST_VECTOR_INDEX$VECPIPELINE')
99+
100+
Profile(profile_name=oci_vector_ai_profile, attributes=ProfileAttributes(annotations=None, case_sensitive_values=None, comments=None, constraints=None, conversation=None, credential_name='my_oci_ai_profile_key', enable_custom_source_uri=None, enable_sources=None, enable_source_offsets=None, enforce_object_list=None, max_tokens=1024, object_list=None, object_list_mode=None, provider=OCIGenAIProvider(embedding_model='cohere.embed-english-v3.0', model=None, provider_name='oci', provider_endpoint=None, region='us-chicago-1', oci_apiformat='GENERIC', oci_compartment_id=None, oci_endpoint_id=None, oci_runtimetype=None), seed=None, stop_tokens=None, streaming=None, temperature=None, vector_index_name='test_vector_index'), description=MY OCI AI Profile)
101+
102+
.. latex:clearpage::
103+
104+
Update vector index attributes
105+
++++++++++++++++++++++++++++++
106+
107+
To update attributes, use either ``vector_index.set_attribute()`` or
108+
``vector_index.set_attributes()``
109+
110+
.. literalinclude:: ../../../samples/vector_index_update_attributes.py
111+
:language: python
112+
:lines: 14-
113+
114+
output::
115+
116+
OracleVectorIndexAttributes(chunk_size=1024, chunk_overlap=128, location='https://objectstorage.us-ashburn-1.oraclecloud.com/n/dwcsdev/b/conda-environment/o/tenant1-pdb3/graph', match_limit=5, object_storage_credential_name='my_oci_ai_profile_key', profile_name='oci_vector_ai_profile', refresh_rate=1450, similarity_threshold=0.5, vector_distance_metric='COSINE', vector_db_endpoint=None, vector_db_credential_name=None, vector_db_provider=<VectorDBProvider.ORACLE: 'oracle'>, vector_dimension=None, vector_table_name=None, pipeline_name='TEST_VECTOR_INDEX$VECPIPELINE')
117+
118+
.. latex:clearpage::
119+
84120
RAG using vector index
85121
++++++++++++++++++++++
86122

@@ -159,6 +195,41 @@ output::
159195

160196
.. latex:clearpage::
161197
198+
199+
Async get vector index attributes
200+
+++++++++++++++++++++++++++++++++
201+
202+
You can fetch the vector index attributes and associated AI profile using
203+
``async_vector_index.get_attributes()`` and ``async_vector_index.get_profile()``
204+
methods respectively.
205+
206+
.. literalinclude:: ../../../samples/async/vector_index_get_attributes.py
207+
:language: python
208+
:lines: 14-
209+
210+
output::
211+
212+
OracleVectorIndexAttributes(chunk_size=1024, chunk_overlap=128, location='https://objectstorage.us-ashburn-1.oraclecloud.com/n/dwcsdev/b/conda-environment/o/tenant1-pdb3/graph', match_limit=5, object_storage_credential_name='my_oci_ai_profile_key', profile_name='oci_vector_ai_profile', refresh_rate=1450, similarity_threshold=0.5, vector_distance_metric='COSINE', vector_db_endpoint=None, vector_db_credential_name=None, vector_db_provider=<VectorDBProvider.ORACLE: 'oracle'>, vector_dimension=None, vector_table_name=None, pipeline_name='TEST_VECTOR_INDEX$VECPIPELINE')
213+
214+
AsyncProfile(profile_name=oci_vector_ai_profile, attributes=ProfileAttributes(annotations=None, case_sensitive_values=None, comments=None, constraints=None, conversation=None, credential_name='my_oci_ai_profile_key', enable_custom_source_uri=None, enable_sources=None, enable_source_offsets=None, enforce_object_list=None, max_tokens=1024, object_list=None, object_list_mode=None, provider=OCIGenAIProvider(embedding_model='cohere.embed-english-v3.0', model=None, provider_name='oci', provider_endpoint=None, region='us-chicago-1', oci_apiformat='GENERIC', oci_compartment_id=None, oci_endpoint_id=None, oci_runtimetype=None), seed=None, stop_tokens=None, streaming=None, temperature=None, vector_index_name='test_vector_index'), description=MY OCI AI Profile)
215+
216+
.. latex:clearpage::
217+
218+
Async update vector index attributes
219+
++++++++++++++++++++++++++++++++++++
220+
221+
To update attributes, use either ``async_vector_index.set_attribute()`` or
222+
``async_vector_index.set_attributes()``
223+
224+
.. literalinclude:: ../../../samples/async/vector_index_update_attributes.py
225+
:language: python
226+
:lines: 14-
227+
228+
output::
229+
230+
OracleVectorIndexAttributes(chunk_size=1024, chunk_overlap=128, location='https://objectstorage.us-ashburn-1.oraclecloud.com/n/dwcsdev/b/conda-environment/o/tenant1-pdb3/graph', match_limit=5, object_storage_credential_name='my_oci_ai_profile_key', profile_name='oci_vector_ai_profile', refresh_rate=1450, similarity_threshold=0.5, vector_distance_metric='COSINE', vector_db_endpoint=None, vector_db_credential_name=None, vector_db_provider=<VectorDBProvider.ORACLE: 'oracle'>, vector_dimension=None, vector_table_name=None, pipeline_name='TEST_VECTOR_INDEX$VECPIPELINE')
231+
232+
162233
Async RAG using vector index
163234
++++++++++++++++++++++++++++
164235

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (c) 2025, Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Universal Permissive License v 1.0 as shown at
5+
# http://oss.oracle.com/licenses/upl.
6+
# -----------------------------------------------------------------------------
7+
8+
# -----------------------------------------------------------------------------
9+
# async/vector_index_get_attributes.py
10+
#
11+
# Get vector index attributes
12+
# -----------------------------------------------------------------------------
13+
14+
import asyncio
15+
import os
16+
17+
import select_ai
18+
19+
user = os.getenv("SELECT_AI_USER")
20+
password = os.getenv("SELECT_AI_PASSWORD")
21+
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
22+
23+
24+
async def main():
25+
await select_ai.async_connect(user=user, password=password, dsn=dsn)
26+
27+
async_vector_index = select_ai.AsyncVectorIndex(
28+
index_name="test_vector_index",
29+
)
30+
attributes = await async_vector_index.get_attributes()
31+
print(attributes)
32+
async_profile = await async_vector_index.get_profile()
33+
print(async_profile)
34+
35+
36+
asyncio.run(main())
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (c) 2025, Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Universal Permissive License v 1.0 as shown at
5+
# http://oss.oracle.com/licenses/upl.
6+
# -----------------------------------------------------------------------------
7+
8+
# -----------------------------------------------------------------------------
9+
# async/vector_index_update_attributes.py
10+
#
11+
# Update Vector index attributes
12+
# -----------------------------------------------------------------------------
13+
14+
import asyncio
15+
import os
16+
17+
import select_ai
18+
19+
user = os.getenv("SELECT_AI_USER")
20+
password = os.getenv("SELECT_AI_PASSWORD")
21+
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
22+
23+
24+
async def main():
25+
await select_ai.async_connect(user=user, password=password, dsn=dsn)
26+
async_vector_index = select_ai.AsyncVectorIndex(
27+
index_name="test_vector_index",
28+
)
29+
30+
# Use vector_index.set_attributes to update a multiple attributes
31+
updated_attributes = select_ai.OracleVectorIndexAttributes(
32+
refresh_rate=1450,
33+
)
34+
await async_vector_index.set_attributes(attributes=updated_attributes)
35+
36+
# Use vector_index.set_attribute to update a single attribute
37+
await async_vector_index.set_attribute(
38+
attribute_name="similarity_threshold", attribute_value=0.5
39+
)
40+
attributes = await async_vector_index.get_attributes()
41+
print(attributes)
42+
43+
44+
asyncio.run(main())
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (c) 2025, Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Universal Permissive License v 1.0 as shown at
5+
# http://oss.oracle.com/licenses/upl.
6+
# -----------------------------------------------------------------------------
7+
8+
# -----------------------------------------------------------------------------
9+
# vector_index_get_attributes.py
10+
#
11+
# Gets attributes for a vector index
12+
# -----------------------------------------------------------------------------
13+
14+
import os
15+
16+
import select_ai
17+
18+
user = os.getenv("SELECT_AI_USER")
19+
password = os.getenv("SELECT_AI_PASSWORD")
20+
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
21+
22+
select_ai.connect(user=user, password=password, dsn=dsn)
23+
24+
vector_index = select_ai.VectorIndex(
25+
index_name="test_vector_index",
26+
)
27+
28+
print(vector_index.get_attributes())
29+
print(vector_index.get_profile())
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (c) 2025, Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Universal Permissive License v 1.0 as shown at
5+
# http://oss.oracle.com/licenses/upl.
6+
# -----------------------------------------------------------------------------
7+
8+
# -----------------------------------------------------------------------------
9+
# vector_index_update_attributes.py
10+
#
11+
# Update attributes for a vector index
12+
# -----------------------------------------------------------------------------
13+
14+
import os
15+
16+
import select_ai
17+
18+
user = os.getenv("SELECT_AI_USER")
19+
password = os.getenv("SELECT_AI_PASSWORD")
20+
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
21+
select_ai.connect(user=user, password=password, dsn=dsn)
22+
vector_index = select_ai.VectorIndex(
23+
index_name="test_vector_index",
24+
)
25+
26+
# Use vector_index.set_attributes to update a multiple attributes
27+
updated_attributes = select_ai.OracleVectorIndexAttributes(
28+
refresh_rate=1450,
29+
)
30+
vector_index.set_attributes(attributes=updated_attributes)
31+
32+
# Use vector_index.set_attribute to update a single attribute
33+
vector_index.set_attribute(
34+
attribute_name="similarity_threshold", attribute_value=0.5
35+
)
36+
print(vector_index.get_attributes())

src/select_ai/async_profile.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
import pandas
2222

2323
from select_ai.action import Action
24-
from select_ai.base_profile import BaseProfile, ProfileAttributes
24+
from select_ai.base_profile import (
25+
BaseProfile,
26+
ProfileAttributes,
27+
no_data_for_prompt,
28+
)
2529
from select_ai.conversation import AsyncConversation
2630
from select_ai.db import async_cursor, async_get_connection
2731
from select_ai.errors import ProfileExistsError, ProfileNotFoundError
@@ -347,10 +351,10 @@ async def generate(
347351
result = await data.read()
348352
else:
349353
result = None
350-
if action == Action.RUNSQL and result:
354+
if action == Action.RUNSQL:
355+
if no_data_for_prompt(result): # empty dataframe
356+
return pandas.DataFrame()
351357
return pandas.DataFrame(json.loads(result))
352-
elif action == Action.RUNSQL:
353-
return pandas.DataFrame()
354358
else:
355359
return result
356360

src/select_ai/base_profile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ProfileAttributes(SelectAIDataClass):
5959
constraints: Optional[str] = None
6060
conversation: Optional[bool] = None
6161
credential_name: Optional[str] = None
62+
enable_custom_source_uri: Optional[bool] = None
6263
enable_sources: Optional[bool] = None
6364
enable_source_offsets: Optional[bool] = None
6465
enforce_object_list: Optional[bool] = None
@@ -182,3 +183,11 @@ def __repr__(self):
182183
f"{self.__class__.__name__}(profile_name={self.profile_name}, "
183184
f"attributes={self.attributes}, description={self.description})"
184185
)
186+
187+
188+
def no_data_for_prompt(result) -> bool:
189+
if result is None:
190+
return True
191+
if result == "No data found for the prompt.":
192+
return True
193+
return False

src/select_ai/profile.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616
from select_ai import Conversation
1717
from select_ai.action import Action
18-
from select_ai.base_profile import BaseProfile, ProfileAttributes
18+
from select_ai.base_profile import (
19+
BaseProfile,
20+
ProfileAttributes,
21+
no_data_for_prompt,
22+
)
1923
from select_ai.db import cursor
2024
from select_ai.errors import ProfileExistsError, ProfileNotFoundError
2125
from select_ai.provider import Provider
@@ -319,10 +323,10 @@ def generate(
319323
result = data.read()
320324
else:
321325
result = None
322-
if action == Action.RUNSQL and result:
326+
if action == Action.RUNSQL:
327+
if no_data_for_prompt(result): # empty dataframe
328+
return pandas.DataFrame()
323329
return pandas.DataFrame(json.loads(result))
324-
elif action == Action.RUNSQL:
325-
return pandas.DataFrame()
326330
else:
327331
return result
328332

0 commit comments

Comments
 (0)