Skip to content

Commit 0b67e9d

Browse files
authored
Merge branch 'main' into aliottoman-patch-8
2 parents fd301b7 + c0b9bfc commit 0b67e9d

File tree

22 files changed

+276
-117
lines changed

22 files changed

+276
-117
lines changed

ai/gen-ai-agents/custom_rag_agent/config.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@
3131

3232
# embeddings
3333
EMBED_MODEL_ID = "cohere.embed-multilingual-v3.0"
34+
# EMBED_MODEL_ID = "cohere.embed-multilingual-image-v3.0"
3435

3536
# LLM
3637
# this is the default model
3738
LLM_MODEL_ID = "meta.llama-3.3-70b-instruct"
3839
TEMPERATURE = 0.1
39-
MAX_TOKENS = 1024
40+
MAX_TOKENS = 2048
4041

4142
# for the UI
4243
LANGUAGE_LIST = ["same as the question", "en", "fr", "it", "es"]
43-
MODEL_LIST = ["meta.llama-3.3-70b-instruct", "cohere.command-r-plus-08-2024"]
44+
# replaced command-r with command-a
45+
MODEL_LIST = ["meta.llama-3.3-70b-instruct", "cohere.command-a-03-2025"]
4446

4547
ENABLE_USER_FEEDBACK = True
4648

4749
# semantic search
4850
TOP_K = 6
49-
COLLECTION_LIST = ["BOOKS", "CNAF"]
51+
COLLECTION_LIST = ["DEV_COACHING", "BOOKS", "CNAF"]
5052

5153
# OCI general
5254
COMPARTMENT_ID = "ocid1.compartment.oc1..aaaaaaaaushuwb2evpuf7rcpl4r7ugmqoe7ekmaiik3ra3m7gec3d234eknq"
@@ -69,3 +71,8 @@
6971
# for loading
7072
CHUNK_SIZE = 2000
7173
CHUNK_OVERLAP = 100
74+
75+
# for MCP server
76+
TRANSPORT = "streamable-http"
77+
HOST = "0.0.0.0"
78+
PORT = 9000
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"""
2+
Semantic Search exposed as an MCP tool
3+
4+
Author: L. Saetta
5+
License: MIT
6+
"""
7+
8+
from typing import Annotated
9+
from pydantic import Field
10+
import oracledb
11+
from fastmcp import FastMCP
12+
from langchain_community.vectorstores.utils import DistanceStrategy
13+
from langchain_community.embeddings import OCIGenAIEmbeddings
14+
from langchain_community.vectorstores.oraclevs import OracleVS
15+
from utils import get_console_logger
16+
17+
from config import DEBUG
18+
from config import AUTH, EMBED_MODEL_ID, SERVICE_ENDPOINT, COMPARTMENT_ID
19+
from config import TRANSPORT, HOST, PORT
20+
from config_private import CONNECT_ARGS
21+
22+
logger = get_console_logger()
23+
24+
mcp = FastMCP("Demo Semantic Search as MCP server")
25+
26+
27+
#
28+
# Helper functions
29+
#
30+
def get_connection():
31+
"""
32+
get a connection to the DB
33+
"""
34+
return oracledb.connect(**CONNECT_ARGS)
35+
36+
37+
def get_embedding_model():
38+
"""
39+
Create the Embedding Model
40+
"""
41+
embed_model = OCIGenAIEmbeddings(
42+
auth_type=AUTH,
43+
model_id=EMBED_MODEL_ID,
44+
service_endpoint=SERVICE_ENDPOINT,
45+
compartment_id=COMPARTMENT_ID,
46+
)
47+
return embed_model
48+
49+
50+
@mcp.tool
51+
def semantic_search(
52+
query: Annotated[
53+
str, Field(description="The search query to find relevant documents.")
54+
],
55+
top_k: Annotated[int, Field(description="TOP_K parameter for search")] = 5,
56+
collection_name: Annotated[
57+
str, Field(description="The name of DB table")
58+
] = "BOOKS",
59+
) -> dict:
60+
"""
61+
Perform a semantic search based on the provided query.
62+
Args:
63+
query (str): The search query.
64+
top_k (int): The number of top results to return.
65+
Returns:
66+
dict: a dictionary containing the relevant documents.
67+
"""
68+
try:
69+
# must be the same embedding model used during load in the Vector Store
70+
embed_model = get_embedding_model()
71+
72+
# get a connection to the DB and init VS
73+
with get_connection() as conn:
74+
v_store = OracleVS(
75+
client=conn,
76+
table_name=collection_name,
77+
distance_strategy=DistanceStrategy.COSINE,
78+
embedding_function=embed_model,
79+
)
80+
81+
relevant_docs = v_store.similarity_search(query=query, k=top_k)
82+
83+
if DEBUG:
84+
logger.info("Result from similarity search:")
85+
logger.info(relevant_docs)
86+
87+
except Exception as e:
88+
logger.error("Error in vector_store.invoke: %s", e)
89+
error = str(e)
90+
return {"error": error}
91+
92+
result = {"relevant_docs": relevant_docs}
93+
94+
return result
95+
96+
@mcp.tool
97+
def get_collections() -> list:
98+
"""
99+
Get the list of collections (DB tables) available in the Oracle Vector Store.
100+
Returns:
101+
list: A list of collection names.
102+
"""
103+
with get_connection() as conn:
104+
cursor = conn.cursor()
105+
106+
cursor.execute(
107+
"""SELECT DISTINCT utc.table_name
108+
FROM user_tab_columns utc
109+
WHERE utc.data_type = 'VECTOR'
110+
ORDER BY 1 ASC"""
111+
)
112+
collections = [row[0] for row in cursor.fetchall()]
113+
return collections
114+
115+
if __name__ == "__main__":
116+
mcp.run(
117+
transport=TRANSPORT,
118+
# Bind to all interfaces
119+
host=HOST,
120+
port=PORT,
121+
log_level="INFO",
122+
)

app-dev/devops-and-containers/oke/oke-rm/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ This stack is used to create the initial network infrastructure for OKE. When co
1616
* By default, everything is private, but there is the possibility to create public subnets
1717
* Be careful when modifying the default values, as inputs are not validated
1818

19-
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/technology-engineering/releases/download/oke-rm-1.1.1/infra.zip)
19+
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/technology-engineering/releases/download/oke-rm-1.1.2/infra.zip)
2020

2121
## Step 2: Create the OKE control plane
2222

2323
This stack is used to create the OKE control plane ONLY.
2424

25-
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/technology-engineering/releases/download/oke-rm-1.1.1/oke.zip)
25+
[![Deploy to Oracle Cloud](https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg)](https://cloud.oracle.com/resourcemanager/stacks/create?zipUrl=https://github.com/oracle-devrel/technology-engineering/releases/download/oke-rm-1.1.2/oke.zip)
2626

2727
Also note that if the network infrastructure is located in a different compartment than the OKE cluster AND you are planning to use the OCI_VCN_NATIVE CNI,
2828
you must add these policies:
95 Bytes
Binary file not shown.

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/bastion-sl.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "oci_core_security_list" "bastion_security_list" {
33
vcn_id = local.vcn_id
44
display_name = "bastion-sec-list"
55
ingress_security_rules {
6-
protocol = "6"
6+
protocol = local.tcp_protocol
77
source_type = "CIDR_BLOCK"
88
source = "0.0.0.0/0"
99
description = "Allow SSH connections to the subnet. Can be deleted if only using OCI Bastion subnet"

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/cp-nsg.tf

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "oci_core_network_security_group" "cp_nsg" {
77
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_1" {
88
direction = "INGRESS"
99
network_security_group_id = oci_core_network_security_group.cp_nsg.id
10-
protocol = "6"
10+
protocol = local.tcp_protocol
1111
source_type = "NETWORK_SECURITY_GROUP"
1212
source = oci_core_network_security_group.worker_nsg.id
1313
stateless = false
@@ -23,7 +23,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_1"
2323
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_2" {
2424
direction = "INGRESS"
2525
network_security_group_id = oci_core_network_security_group.cp_nsg.id
26-
protocol = "6"
26+
protocol = local.tcp_protocol
2727
source_type = "NETWORK_SECURITY_GROUP"
2828
source = oci_core_network_security_group.cp_nsg.id
2929
stateless = false
@@ -39,7 +39,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_2"
3939
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_3" {
4040
direction = "INGRESS"
4141
network_security_group_id = oci_core_network_security_group.cp_nsg.id
42-
protocol = "6"
42+
protocol = local.tcp_protocol
4343
source_type = "CIDR_BLOCK"
4444
source = var.bastion_subnet_cidr
4545
stateless = false
@@ -57,7 +57,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_3"
5757
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_4" {
5858
direction = "INGRESS"
5959
network_security_group_id = oci_core_network_security_group.cp_nsg.id
60-
protocol = "6"
60+
protocol = local.tcp_protocol
6161
source_type = "NETWORK_SECURITY_GROUP"
6262
source = oci_core_network_security_group.pod_nsg.0.id
6363
stateless = false
@@ -74,7 +74,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_4"
7474
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_5" {
7575
direction = "INGRESS"
7676
network_security_group_id = oci_core_network_security_group.cp_nsg.id
77-
protocol = "6"
77+
protocol = local.tcp_protocol
7878
source_type = "NETWORK_SECURITY_GROUP"
7979
source = oci_core_network_security_group.pod_nsg.0.id
8080
stateless = false
@@ -91,7 +91,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_5"
9191
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_6" {
9292
direction = "INGRESS"
9393
network_security_group_id = oci_core_network_security_group.cp_nsg.id
94-
protocol = "6"
94+
protocol = local.tcp_protocol
9595
source_type = "NETWORK_SECURITY_GROUP"
9696
source = oci_core_network_security_group.worker_nsg.id
9797
stateless = false
@@ -107,7 +107,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_6"
107107
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_7" {
108108
direction = "INGRESS"
109109
network_security_group_id = oci_core_network_security_group.cp_nsg.id
110-
protocol = "1"
110+
protocol = local.icmp_protocol
111111
source_type = "NETWORK_SECURITY_GROUP"
112112
source = oci_core_network_security_group.worker_nsg.id
113113
stateless = false
@@ -121,7 +121,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_7"
121121
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_8" {
122122
direction = "INGRESS"
123123
network_security_group_id = oci_core_network_security_group.cp_nsg.id
124-
protocol = "6"
124+
protocol = local.tcp_protocol
125125
source_type = "CIDR_BLOCK"
126126
source = var.cp_allowed_source_cidr
127127
stateless = false
@@ -137,7 +137,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_ingress_8"
137137
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_1" {
138138
direction = "EGRESS"
139139
network_security_group_id = oci_core_network_security_group.cp_nsg.id
140-
protocol = "6"
140+
protocol = local.tcp_protocol
141141
destination_type = "NETWORK_SECURITY_GROUP"
142142
destination = oci_core_network_security_group.worker_nsg.id
143143
stateless = false
@@ -153,7 +153,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_1" {
153153
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_2" {
154154
direction = "EGRESS"
155155
network_security_group_id = oci_core_network_security_group.cp_nsg.id
156-
protocol = "6"
156+
protocol = local.tcp_protocol
157157
destination_type = "NETWORK_SECURITY_GROUP"
158158
destination = oci_core_network_security_group.pod_nsg.0.id
159159
stateless = false
@@ -165,7 +165,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_2" {
165165
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_3" {
166166
direction = "EGRESS"
167167
network_security_group_id = oci_core_network_security_group.cp_nsg.id
168-
protocol = "6"
168+
protocol = local.tcp_protocol
169169
destination_type = "SERVICE_CIDR_BLOCK"
170170
destination = lookup(data.oci_core_services.all_oci_services.services[0], "cidr_block")
171171
stateless = false
@@ -176,7 +176,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_3" {
176176
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_4" {
177177
direction = "EGRESS"
178178
network_security_group_id = oci_core_network_security_group.cp_nsg.id
179-
protocol = "6"
179+
protocol = local.tcp_protocol
180180
destination_type = "NETWORK_SECURITY_GROUP"
181181
destination = oci_core_network_security_group.worker_nsg.id
182182
stateless = false
@@ -193,7 +193,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_4" {
193193
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_5" {
194194
direction = "EGRESS"
195195
network_security_group_id = oci_core_network_security_group.cp_nsg.id
196-
protocol = "6"
196+
protocol = local.tcp_protocol
197197
destination_type = "NETWORK_SECURITY_GROUP"
198198
destination = oci_core_network_security_group.cp_nsg.id
199199
stateless = false
@@ -209,7 +209,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_5" {
209209
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_6" {
210210
direction = "EGRESS"
211211
network_security_group_id = oci_core_network_security_group.cp_nsg.id
212-
protocol = "1"
212+
protocol = local.icmp_protocol
213213
destination_type = "NETWORK_SECURITY_GROUP"
214214
destination = oci_core_network_security_group.worker_nsg.id
215215
stateless = false
@@ -223,7 +223,7 @@ resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_6" {
223223
resource "oci_core_network_security_group_security_rule" "oke_cp_nsg_egress_7" {
224224
direction = "EGRESS"
225225
network_security_group_id = oci_core_network_security_group.cp_nsg.id
226-
protocol = "6"
226+
protocol = local.tcp_protocol
227227
destination_type = "CIDR_BLOCK"
228228
destination = var.cp_egress_cidr
229229
stateless = false

app-dev/devops-and-containers/oke/oke-rm/infra/modules/network/fss-nsg.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "oci_core_network_security_group" "fss_nsg" {
77
resource "oci_core_network_security_group_security_rule" "fss_ingress_rule_1" {
88
direction = "INGRESS"
99
network_security_group_id = oci_core_network_security_group.fss_nsg.id
10-
protocol = "17" # UDP
10+
protocol = local.udp_protocol
1111
source_type = "NETWORK_SECURITY_GROUP"
1212
source = oci_core_network_security_group.worker_nsg.id
1313
stateless = false
@@ -23,7 +23,7 @@ resource "oci_core_network_security_group_security_rule" "fss_ingress_rule_1" {
2323
resource "oci_core_network_security_group_security_rule" "fss_ingress_rule_2" {
2424
direction = "INGRESS"
2525
network_security_group_id = oci_core_network_security_group.fss_nsg.id
26-
protocol = "6"
26+
protocol = local.tcp_protocol
2727
source_type = "NETWORK_SECURITY_GROUP"
2828
source = oci_core_network_security_group.worker_nsg.id
2929
stateless = false
@@ -39,7 +39,7 @@ resource "oci_core_network_security_group_security_rule" "fss_ingress_rule_2" {
3939
resource "oci_core_network_security_group_security_rule" "fss_ingress_rule_3" {
4040
direction = "INGRESS"
4141
network_security_group_id = oci_core_network_security_group.fss_nsg.id
42-
protocol = "17" # UDP
42+
protocol = local.udp_protocol
4343
source_type = "NETWORK_SECURITY_GROUP"
4444
source = oci_core_network_security_group.worker_nsg.id
4545
stateless = false
@@ -55,7 +55,7 @@ resource "oci_core_network_security_group_security_rule" "fss_ingress_rule_3" {
5555
resource "oci_core_network_security_group_security_rule" "fss_ingress_rule_4" {
5656
direction = "INGRESS"
5757
network_security_group_id = oci_core_network_security_group.fss_nsg.id
58-
protocol = "6"
58+
protocol = local.tcp_protocol
5959
source_type = "NETWORK_SECURITY_GROUP"
6060
source = oci_core_network_security_group.worker_nsg.id
6161
stateless = false
@@ -71,7 +71,7 @@ resource "oci_core_network_security_group_security_rule" "fss_ingress_rule_4" {
7171
resource "oci_core_network_security_group_security_rule" "fss_ingress_rule_5" {
7272
direction = "INGRESS"
7373
network_security_group_id = oci_core_network_security_group.fss_nsg.id
74-
protocol = "6"
74+
protocol = local.tcp_protocol
7575
source_type = "NETWORK_SECURITY_GROUP"
7676
source = oci_core_network_security_group.worker_nsg.id
7777
stateless = false

0 commit comments

Comments
 (0)