Install the Python SDK
The Python SDK, oracle-vecdb, is distributed using Python’s package repository (PyPI) and can be installed using pip.
First ensure that Python is installed on your system. The versions supported with oracle-vecdb are Python
3.10 and later. You can check your version using the following command:
python --version
Note: On some platforms, the Python executable may be called python3 instead of python.
Run the following command to install or upgrade oracle-vecdb:
python -m pip install oracle-vecdb --upgrade
Using python -m pip ensures that the package is installed for the same Python interpreter that you are running.
If you are not using a virtual environment and do not have permission to install packages system-wide, you can choose to append the --user option to the end of the install command to indicate a user-level installation.
You can verify the installation by importing the oracle_vecdb package in Python:
python -c "import oracle_vecdb"
If no error is raised, the installation was successful.
Once you have installed the Python SDK, you can follow this example to first create a client and then create a table, upsert vectors, and perform a simple semantic search. Note that you will need to input your own host and access_token (or username and password) values to create the client.
from oracle_vecdb import OracleVecDB, Configuration
cfg = Configuration(
rest_url="https://<host>/ords/<schema>/_/db-api/stable/vecdb/",
# choose one auth method
access_token="<bearer-token>", # preferred
# or username="<user>", password="<pass>", # basic
)
vecdb = OracleVecDB(cfg)
# Create a table
vecdb.create_vector_table(table_name="demo")
# Upsert a couple of vectors
vecdb.upsert_vectors(
table_name="demo",
vectors=[
{"id": "1", "dense_vector": [0.1, 0.1], "metadata": {"genre": "comedy"}},
{"id": "2", "dense_vector": [0.2, 0.2], "metadata": {"genre": "drama"}},
],
)
# Query by vector
results = vecdb.query(
table_name="demo",
query_by={"vector": [0.15, 0.1]},
filters={'genre': {'$eq': 'drama'}},
top_k=1,
)
print(results)
Note: Proxies and retries can be configured using Configuration.
For more in depth examples that demonstrate how to use Autonomous AI Vector Database, see the following resources on GitHub: