-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Add Oracle Integrations #6026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fileames
wants to merge
4
commits into
crewAIInc:main
Choose a base branch
from
fileames:oracle_integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Oracle Integrations #6026
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
197 changes: 197 additions & 0 deletions
197
lib/crewai-tools/src/crewai_tools/tools/oracle_vector_search_tool/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| # OracleVectorSearchTool | ||
|
|
||
| ## Description | ||
|
|
||
| This tool is specifically crafted for conducting vector searches within Oracle AI Vector Search tables. Use this tool to find semantically similar documents stored in Oracle Database. | ||
|
|
||
| Oracle Database 23ai and later can store vectors natively and query them with `vector_distance(...)`. This tool follows CrewAI's existing vector-search tool shape while using Oracle-native SQL under the hood. | ||
|
|
||
| ## Installation | ||
|
|
||
| Install the CrewAI tools package with Oracle support: | ||
|
|
||
| ```shell | ||
| pip install crewai-tools[oracledb] | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| ```shell | ||
| uv add crewai-tools --extra oracledb | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| ```python | ||
| import os | ||
|
|
||
| from crewai_tools import ( | ||
| OracleVectorSearchConfig, | ||
| OracleVectorSearchQueryConfig, | ||
| OracleVectorSearchTool, | ||
| ) | ||
|
|
||
| tool = OracleVectorSearchTool( | ||
| oracle_config=OracleVectorSearchConfig( | ||
| user=os.environ["ORACLE_DB_USERNAME"], | ||
| password=os.environ["ORACLE_DB_SECRET"], | ||
| dsn=os.environ["ORACLE_DB_DSN"], | ||
| table_name="DOCS_VECTORS", | ||
| limit=3, | ||
| distance_strategy="COSINE", | ||
| ), | ||
| query_config=OracleVectorSearchQueryConfig( | ||
| score_threshold=0.6, | ||
| filter={"source": "docs"}, | ||
| ), | ||
| ) | ||
| ``` | ||
|
|
||
| Running a search with native JSON numeric filtering: | ||
|
|
||
| ```python | ||
| results = tool._run( | ||
| query="oracle vector", | ||
| filter_by="priority", | ||
| filter_value=5, | ||
| score_threshold=0.6, | ||
| ) | ||
| ``` | ||
|
|
||
| Using richer Oracle-style filters: | ||
|
|
||
| ```python | ||
| results = tool._run( | ||
| query="oracle vector", | ||
| filters='{"$or":[{"source":"docs"},{"priority":{"$gte":3}}]}', | ||
| ) | ||
| ``` | ||
|
|
||
| Using a custom embedding function: | ||
|
|
||
| ```python | ||
| import os | ||
|
|
||
| tool = OracleVectorSearchTool( | ||
| oracle_config=OracleVectorSearchConfig( | ||
| user=os.environ["ORACLE_DB_USERNAME"], | ||
| password=os.environ["ORACLE_DB_SECRET"], | ||
| dsn=os.environ["ORACLE_DB_DSN"], | ||
| table_name="DOCS_VECTORS", | ||
| ), | ||
| embedding_function=my_embedding_function, | ||
| ) | ||
| ``` | ||
|
|
||
| Passing additional `oracledb.connect()` options: | ||
|
|
||
| ```python | ||
| import os | ||
|
|
||
| tool = OracleVectorSearchTool( | ||
| oracle_config=OracleVectorSearchConfig( | ||
| user=os.environ["ORACLE_DB_USERNAME"], | ||
| password=os.environ["ORACLE_DB_SECRET"], | ||
| dsn=os.environ["ORACLE_DB_DSN"], | ||
| table_name="DOCS_VECTORS", | ||
| connection_kwargs={ | ||
| "config_dir": "/path/to/wallet", | ||
| "wallet_location": "/path/to/wallet", | ||
| }, | ||
| ), | ||
| embedding_function=my_embedding_function, | ||
| ) | ||
| ``` | ||
|
|
||
| Using a caller-managed connection pool: | ||
|
|
||
| ```python | ||
| import os | ||
|
|
||
| import oracledb | ||
|
|
||
| pool = oracledb.create_pool( | ||
| user=os.environ["ORACLE_DB_USERNAME"], | ||
| password=os.environ["ORACLE_DB_SECRET"], | ||
| dsn=os.environ["ORACLE_DB_DSN"], | ||
| min=1, | ||
| max=4, | ||
| ) | ||
|
|
||
| tool = OracleVectorSearchTool( | ||
| oracle_config=OracleVectorSearchConfig(table_name="DOCS_VECTORS"), | ||
| client=pool, | ||
| embedding_function=my_embedding_function, | ||
| ) | ||
| ``` | ||
|
|
||
| Preloading data into Oracle: | ||
|
|
||
| ```python | ||
| tool.create_table() | ||
| tool.add_texts( | ||
| ["CrewAI integrates with Oracle AI Vector Search."], | ||
| metadatas=[{"source": "docs"}], | ||
| ) | ||
| tool.create_vector_index( | ||
| idx_type="HNSW", | ||
| params={"accuracy": 90, "neighbors": 32, "efconstruction": 200, "parallel": 8}, | ||
| ) | ||
|
|
||
| # Or create an IVF index instead. | ||
| tool.create_vector_index( | ||
| index_name="DOCS_IVF_IDX", | ||
| idx_type="IVF", | ||
| params={ | ||
| "accuracy": 90, | ||
| "neighbor_partitions": 32, | ||
| "samples_per_partition": 1, | ||
| "min_vectors_per_partition": 0, | ||
| "parallel": 8, | ||
| }, | ||
| ) | ||
| ``` | ||
|
|
||
| ## Arguments | ||
|
|
||
| - `oracle_config`: Oracle connection and search settings. Required. | ||
| - `query_config`: Optional default query behavior including `limit`, `score_threshold`, and Oracle-style metadata filters. | ||
| - `embedding_function`: Optional callable used instead of OpenAI embeddings. | ||
| - `embedding_model`: OpenAI embedding model used when `embedding_function` is not provided. | ||
| - `dimensions`: Embedding dimension used when creating tables and validating inserted embeddings. | ||
|
|
||
| `oracle_config` supports: | ||
|
|
||
| - `user`, `password`, `dsn`: Common Oracle connection fields when a client is not provided. | ||
| - `connection_kwargs`: Optional extra keyword arguments passed to `oracledb.connect()` when the tool creates the connection. | ||
| - `table_name`: Oracle table containing your text, metadata, and vector columns. | ||
| - `limit`: Number of search results to return. | ||
| - `score_threshold`: Optional maximum vector distance. Only rows with `distance <= score_threshold` are returned. | ||
| - `distance_strategy`: One of `COSINE`, `EUCLIDEAN`, or `DOT`. | ||
| - `index_name`: Optional default vector index name used by `create_vector_index()`. | ||
|
|
||
| `create_vector_index()` supports: | ||
|
|
||
| - `idx_type`: `HNSW` or `IVF`. Defaults to `HNSW`. | ||
| - `params`: Oracle vector index parameters. For `HNSW`, use `accuracy`, `neighbors`, `efconstruction`, and `parallel`. For `IVF`, use `accuracy`, `neighbor_partitions`, `samples_per_partition`, `min_vectors_per_partition`, and `parallel`. | ||
|
|
||
| `client` may be a caller-managed `oracledb.Connection` or `oracledb.ConnectionPool`. Pools must be created by the caller and passed through `client`; `OracleVectorSearchConfig` only configures single connections created with `oracledb.connect()`. | ||
|
|
||
| The tool creates and expects a fixed Oracle schema: | ||
| - `id` | ||
| - `text` | ||
| - `metadata` as native Oracle `JSON` | ||
| - `embedding` | ||
|
|
||
| `_run()` also supports: | ||
|
|
||
| - `filters`: JSON string for richer Oracle metadata filters such as `{"$or":[{"source":"docs"},{"topic":{"$eq":"oracle"}}]}` | ||
| - `limit`: Per-call result limit override | ||
| - `score_threshold`: Per-call maximum distance override | ||
|
|
||
| Result format: | ||
|
|
||
| - `context`: The matched text payload. | ||
| - `metadata`: Oracle JSON metadata decoded back into Python values. | ||
| - `distance`: Raw Oracle `vector_distance(...)` value. | ||
| - `score`: Kept for consistency with other CrewAI vector tools, but currently equal to `distance`. | ||
14 changes: 14 additions & 0 deletions
14
lib/crewai-tools/src/crewai_tools/tools/oracle_vector_search_tool/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from crewai_tools.tools.oracle_vector_search_tool.vector_search import ( | ||
| OracleToolSchema, | ||
| OracleVectorSearchConfig, | ||
| OracleVectorSearchQueryConfig, | ||
| OracleVectorSearchTool, | ||
| ) | ||
|
|
||
|
|
||
| __all__ = [ | ||
| "OracleToolSchema", | ||
| "OracleVectorSearchConfig", | ||
| "OracleVectorSearchQueryConfig", | ||
| "OracleVectorSearchTool", | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.