Skip to content

Commit 5b040d6

Browse files
committed
semantic - OpenSearch 도메인 연결
1 parent 6dcfe07 commit 5b040d6

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

rag_implement_by_suing_opensearch/semantic_search.py

+54-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,57 @@ def find_long_plot_items(df):
3535
long_plot_items = df[df["plot"].str.len() > 512]
3636
return long_plot_items
3737

38-
find_long_plot_items(df).count()
38+
find_long_plot_items(df).count()
39+
40+
#3.오픈서치 도메인에 연결
41+
def get_cfn_outputs(stackname, cfn):
42+
outputs = {}
43+
for output in cfn.describe_stacks(StackName=stackname)["Stacks"][0]["Outputs"]:
44+
outputs[output["OutputKey"]] = output["OutputValue"]
45+
return outputs
46+
47+
import boto3, json
48+
49+
50+
region_name = "us-east-1"
51+
52+
cfn = boto3.client("cloudformation", region_name)
53+
kms = boto3.client("secretsmanager", region_name)
54+
55+
stackname = "opensearch-workshop"
56+
cfn_outputs = get_cfn_outputs(stackname, cfn)
57+
58+
aos_credentials = json.loads(
59+
kms.get_secret_value(SecretId=cfn_outputs["OpenSearchSecret"])["SecretString"]
60+
)
61+
62+
aos_host = cfn_outputs["OpenSearchDomainEndpoint"]
63+
aos_host
64+
65+
import boto3, json
66+
region_name = "us-west-2"
67+
68+
cfn = boto3.client("cloudformation", region_name)
69+
kms = boto3.client("secretsmanager", region_name)
70+
71+
stackname = "opensearch-workshop"
72+
cfn_outputs = get_cfn_outputs(stackname, cfn)
73+
74+
aos_credentials = json.loads(
75+
kms.get_secret_value(SecretId=cfn_outputs["OpenSearchSecret"])["SecretString"]
76+
)
77+
78+
aos_host = cfn_outputs["OpenSearchDomainEndpoint"]
79+
aos_host
80+
81+
from opensearchpy import OpenSearch, RequestsHttpConnection, AWSV4SignerAuth
82+
83+
auth = (aos_credentials["username"], aos_credentials["password"])
84+
85+
aos_client = OpenSearch(
86+
hosts=[{"host": aos_host, "port": 443}],
87+
http_auth=auth,
88+
use_ssl=True,
89+
verify_certs=True,
90+
connection_class=RequestsHttpConnection,
91+
)

0 commit comments

Comments
 (0)