Skip to content

Commit 810a344

Browse files
authored
Merge pull request #156 from oracle-samples/112-selectai-integration
SelectAI Tool initial commit
2 parents 2ddb48c + 74cfde9 commit 810a344

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2274
-2132
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ __pycache__/
4545
**/**.tfvars
4646
**/.terraform*
4747
**/terraform.tfstate*
48+
**/*.pem
4849
opentofu/**/generated/*.*
4950
opentofu/**/generated/kubeconfig
5051

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
The **Oracle AI Optimizer and Toolkit** (the **AI Optimizer**) provides a streamlined environment where developers and data scientists can explore the potential of Generative Artificial Intelligence (GenAI) combined with Retrieval-Augmented Generation (RAG) capabilities. By integrating **Oracle Database 23ai** AI Vector Search, the Sandbox enables users to enhance existing Large Language Models (LLMs) through RAG.
7+
The **Oracle AI Optimizer and Toolkit** (the **AI Optimizer**) provides a streamlined environment where developers and data scientists can explore the potential of Generative Artificial Intelligence (GenAI) combined with Retrieval-Augmented Generation (RAG) capabilities. By integrating **Oracle Database 23ai** AI VectorSearch and SelectAI, the Sandbox enables users to enhance existing Large Language Models (LLMs) through RAG.
88

99
## AI Optimizer Features
1010

docs/content/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Licensed under the Universal Permissive License v1.0 as shown at http://oss.orac
1313
spell-checker:ignore streamlit, genai, venv
1414
-->
1515

16-
The {{< full_app_ref >}} provides a streamlined environment where developers and data scientists can explore the potential of Generative Artificial Intelligence (**GenAI**) combined with Retrieval-Augmented Generation (**RAG**) capabilities. By integrating Oracle Database AI Vector Search, the {{< short_app_ref >}} enables users to enhance existing Large Language Models (**LLM**s) through **RAG**. This method significantly improves the performance and accuracy of AI models, helping to avoid common issues such as knowledge cutoff and hallucinations.
16+
The {{< full_app_ref >}} provides a streamlined environment where developers and data scientists can explore the potential of Generative Artificial Intelligence (**GenAI**) combined with Retrieval-Augmented Generation (**RAG**) capabilities. By integrating Oracle Database AI VectorSearch and SelectAI, the {{< short_app_ref >}} enables users to enhance existing Large Language Models (**LLM**s) through **RAG**. This method significantly improves the performance and accuracy of AI models, helping to avoid common issues such as knowledge cutoff and hallucinations.
1717

1818
- **GenAI**: Powers the generation of text, images, or other data based on prompts using pre-trained **LLM**s.
1919
- **RAG**: Enhances **LLM**s by retrieving relevant, real-time information allowing models to provide up-to-date and accurate responses.

docs/content/client/configuration/db_config.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ For container installations, there are a couple of ways to include the contents
8080

8181
## Database User
8282

83-
A database user is required to store the embeddings, used for **RAG**, into the Oracle Database. A non-privileged user with a *non-SYSTEM tablespace* should be used for this purpose. Use the below syntax as an example of creating a new user:
83+
A database user is required to store the embeddings, used for **RAG**, into the Oracle Database. A non-privileged user with a *non-SYSTEM tablespace* should be used for this purpose. Use the below syntax as an __example__ of creating a new user with least privileges:
8484

8585
```sql
8686
CREATE USER "DEMO" IDENTIFIED BY MYCOMPLEXSECRET
@@ -91,7 +91,13 @@ ALTER USER "DEMO" DEFAULT ROLE ALL;
9191
ALTER USER "DEMO" QUOTA UNLIMITED ON DATA;
9292
```
9393

94-
Replace "DEMO" as required.
94+
If running on a supported database for [SelectAI](https://docs.oracle.com/en-us/iaas/autonomous-database-serverless/doc/select-ai.html) and want to use the feature, grant the following additional privileges and open appropriate ACLs:
95+
96+
```sql
97+
GRANT EXECUTE ON DBMS_CLOUD TO DEMO;
98+
GRANT EXECUTE ON DBMS_CLOUD_AI TO DEMO;
99+
GRANT EXECUTE ON DBMS_CLOUD_PIPELINE TO DEMO;
100+
```
95101

96102
{{% notice style="default" title="One schema fits none..." icon="circle-info" %}}
97103
Creating multiple users in the same database allows developers to separate their experiments simply by changing the "Database User"

helm/charts/server/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ spec:
164164
volumes:
165165
- name: tmp
166166
emptyDir: {}
167-
{{- if .Values.adb.enabled }}
167+
{{- if and .Values.adb .Values.adb.enabled }}
168168
- name: tns-admin
169169
secret:
170-
{{- if .Values.adb.tnsAdmin.secretName }}
170+
{{- if and .Values.adb.tnsAdmin .Values.adb.tnsAdmin.secretName }}
171171
secretName: {{ .Values.adb.tnsAdmin.secretName | quote }}
172172
{{ else }}
173173
secretName: {{ include "app.fullname" . }}-adb-tns-admin-{{ .Release.Revision }}

opentofu/iam.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2024, 2025, Oracle and/or its affiliates.
2+
# All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
3+
# spell-checker: disable
4+
5+
resource "oci_identity_tag_namespace" "tag_namespace" {
6+
compartment_id = local.compartment_ocid
7+
description = format("%s Tag Namespace", local.label_prefix)
8+
name = local.label_prefix
9+
provider = oci.home_region
10+
}
11+
12+
resource "oci_identity_tag" "identity_tag" {
13+
description = format("%s Infrastructure", local.label_prefix)
14+
name = "infrastructure"
15+
tag_namespace_id = oci_identity_tag_namespace.tag_namespace.id
16+
provider = oci.home_region
17+
}
18+
19+
resource "oci_identity_dynamic_group" "resource_dynamic_group" {
20+
compartment_id = var.tenancy_ocid
21+
name = format("%s-dyngrp", local.label_prefix)
22+
description = format("%s Dynamic Group", local.label_prefix)
23+
matching_rule = format(
24+
"All {resource.compartment.id = '%s', tag.%s.value = '%s'}",
25+
local.compartment_ocid, local.identity_tag_key, local.label_prefix
26+
)
27+
provider = oci.home_region
28+
}
29+
30+
resource "oci_identity_policy" "adb_policies" {
31+
compartment_id = var.tenancy_ocid
32+
name = format("%s-adb-policy", var.label_prefix)
33+
description = format("%s - ADB", var.label_prefix)
34+
statements = [
35+
format("allow dynamic-group %s to use generative-ai-family in compartment id %s", oci_identity_dynamic_group.resource_dynamic_group.name, local.compartment_ocid),
36+
]
37+
provider = oci.home_region
38+
}

opentofu/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
locals {
77
compartment_ocid = var.compartment_ocid != "" ? var.compartment_ocid : var.tenancy_ocid
88
label_prefix = var.label_prefix != "" ? lower(var.label_prefix) : lower(random_pet.label.id)
9+
identity_tag_key = format("%s.%s", oci_identity_tag_namespace.tag_namespace.name, oci_identity_tag.identity_tag.name)
910
}
1011

1112
// Autonomous Database

opentofu/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ resource "oci_database_autonomous_database" "default_adb" {
7474
license_model = var.adb_license_model
7575
is_mtls_connection_required = true
7676
whitelisted_ips = local.adb_whitelist_cidrs
77+
defined_tags = { (local.identity_tag_key) = local.label_prefix }
7778
}
7879

7980
// Virtual Machine
@@ -112,6 +113,7 @@ module "kubernetes" {
112113
compartment_id = local.compartment_ocid
113114
vcn_id = module.network.vcn_ocid
114115
region = var.region
116+
dynamic_group = oci_identity_dynamic_group.resource_dynamic_group.name
115117
lb = oci_load_balancer_load_balancer.lb
116118
adb_id = oci_database_autonomous_database.default_adb.id
117119
adb_name = local.adb_name
@@ -130,6 +132,7 @@ module "kubernetes" {
130132
public_subnet_id = module.network.public_subnet_ocid
131133
private_subnet_id = module.network.private_subnet_ocid
132134
lb_nsg_id = oci_core_network_security_group.lb.id
135+
identity_tag_key = local.identity_tag_key
133136
providers = {
134137
oci.home_region = oci.home_region
135138
}

opentofu/modules/kubernetes/iam.tf

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,10 @@
22
# All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
33
# spell-checker: disable
44

5-
resource "oci_identity_tag_namespace" "tag_namespace" {
6-
compartment_id = var.compartment_id
7-
description = format("%s Tag Namespace", var.label_prefix)
8-
name = var.label_prefix
9-
provider = oci.home_region
10-
}
11-
12-
resource "oci_identity_tag" "identity_tag" {
13-
description = format("%s Infrastructure", var.label_prefix)
14-
name = "infrastructure"
15-
tag_namespace_id = oci_identity_tag_namespace.tag_namespace.id
16-
provider = oci.home_region
17-
}
18-
19-
resource "oci_identity_dynamic_group" "node_dynamic_group" {
20-
compartment_id = var.tenancy_id
21-
name = format("%s-workers-dyngrp", var.label_prefix)
22-
description = format("%s Dynamic Group - K8s Workers", var.label_prefix)
23-
matching_rule = format(
24-
"All {instance.compartment.id = '%s', tag.%s.value = '%s'}",
25-
var.compartment_id, local.identity_tag_key, local.identity_tag_val
26-
)
27-
provider = oci.home_region
28-
}
29-
30-
resource "oci_identity_policy" "workload_node_policies" {
5+
resource "oci_identity_policy" "workers_policies" {
316
compartment_id = var.tenancy_id
32-
name = format("%s-worker-workload-policy", var.label_prefix)
33-
description = format("%s PrincipleAuth - K8s Workers", var.label_prefix)
7+
name = format("%s-workers-policy", var.label_prefix)
8+
description = format("%s - K8s Workers", var.label_prefix)
349
statements = [
3510
format("allow any-user to manage autonomous-database-family in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'oracle-database-operator-system', request.principal.service_account = 'default', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
3611
format("allow any-user to read objectstorage-namespaces in compartment id %s where all {request.principal.type = 'workload', request.principal.service_account = 'default', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
@@ -52,7 +27,7 @@ resource "oci_identity_policy" "workload_node_policies" {
5227
format("allow any-user to manage waf-family in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
5328
format("allow any-user to read cluster-family in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
5429
format("allow any-user to use tag-namespaces in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
55-
format("allow dynamic-group %s to manage repos in compartment id %s", oci_identity_dynamic_group.node_dynamic_group.name, var.compartment_id),
30+
format("allow dynamic-group %s to manage repos in compartment id %s", var.dynamic_group, var.compartment_id),
5631
]
5732
provider = oci.home_region
5833
}

opentofu/modules/kubernetes/locals.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
// Region Mapping
66
locals {
7-
identity_tag_key = format("%s.%s", oci_identity_tag_namespace.tag_namespace.name, oci_identity_tag.identity_tag.name)
8-
identity_tag_val = var.label_prefix
97
region_map = {
108
for r in data.oci_identity_regions.identity_regions.regions : r.name => r.key
119
}

0 commit comments

Comments
 (0)