Skip to content

Commit d2b7aa8

Browse files
author
zhaoshengbo
committed
clean ipynb output
1 parent b4db893 commit d2b7aa8

File tree

1 file changed

+97
-109
lines changed

1 file changed

+97
-109
lines changed

docs/modules/indexes/vectorstores/examples/alibabacloud_opensearch.ipynb

Lines changed: 97 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5+
"metadata": {
6+
"collapsed": false
7+
},
58
"source": [
69
"# Alibaba Cloud OpenSearch\n",
710
"\n",
@@ -14,23 +17,26 @@
1417
"This notebook shows how to use functionality related to the `Alibaba Cloud OpenSearch Vector Search Edition`.\n",
1518
"To run, you should have an [OpenSearch Vector Search Edition](https://opensearch.console.aliyun.com) instance up and running:\n",
1619
"- Read the [help document](https://www.alibabacloud.com/help/en/opensearch/latest/vector-search) to quickly familiarize and configure OpenSearch Vector Search Edition instance.\n"
17-
],
18-
"metadata": {
19-
"collapsed": false
20-
}
20+
]
2121
},
2222
{
2323
"cell_type": "markdown",
24-
"source": [
25-
"After completing the configuration, follow these steps to connect to the instance, index documents, and perform vector retrieval."
26-
],
2724
"metadata": {
2825
"collapsed": false
29-
}
26+
},
27+
"source": [
28+
"After completing the configuration, follow these steps to connect to the instance, index documents, and perform vector retrieval."
29+
]
3030
},
3131
{
3232
"cell_type": "code",
3333
"execution_count": null,
34+
"metadata": {
35+
"collapsed": false,
36+
"pycharm": {
37+
"name": "#%%\n"
38+
}
39+
},
3440
"outputs": [],
3541
"source": [
3642
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
@@ -39,26 +45,26 @@
3945
" AlibabaCloudOpenSearch,\n",
4046
" AlibabaCloudOpenSearchSettings,\n",
4147
")"
42-
],
43-
"metadata": {
44-
"collapsed": false,
45-
"pycharm": {
46-
"name": "#%%\n"
47-
}
48-
}
48+
]
4949
},
5050
{
5151
"cell_type": "markdown",
52-
"source": [
53-
"Split documents and get embeddings by call OpenAI API"
54-
],
5552
"metadata": {
5653
"collapsed": false
57-
}
54+
},
55+
"source": [
56+
"Split documents and get embeddings by call OpenAI API"
57+
]
5858
},
5959
{
6060
"cell_type": "code",
6161
"execution_count": null,
62+
"metadata": {
63+
"collapsed": false,
64+
"pycharm": {
65+
"name": "#%%\n"
66+
}
67+
},
6268
"outputs": [],
6369
"source": [
6470
"from langchain.document_loaders import TextLoader\n",
@@ -69,28 +75,30 @@
6975
"docs = text_splitter.split_documents(documents)\n",
7076
"\n",
7177
"embeddings = OpenAIEmbeddings()"
72-
],
73-
"metadata": {
74-
"collapsed": false,
75-
"pycharm": {
76-
"name": "#%%\n"
77-
}
78-
}
78+
]
7979
},
8080
{
8181
"cell_type": "markdown",
82-
"source": [
83-
"Create opensearch settings."
84-
],
8582
"metadata": {
8683
"collapsed": false,
8784
"pycharm": {
8885
"name": "#%% md\n"
8986
}
90-
}
87+
},
88+
"source": [
89+
"Create opensearch settings."
90+
]
9191
},
9292
{
9393
"cell_type": "code",
94+
"execution_count": null,
95+
"metadata": {
96+
"collapsed": false,
97+
"pycharm": {
98+
"name": "#%%\n"
99+
}
100+
},
101+
"outputs": [],
94102
"source": [
95103
"settings = AlibabaCloudOpenSearchSettings(\n",
96104
" endpoint=\"The endpoint of opensearch instance, You can find it from the console of Alibaba Cloud OpenSearch.\",\n",
@@ -121,165 +129,145 @@
121129
"# \"embedding\": \"embedding\",\n",
122130
"# \"metadata\": \"metadata,=\" #The value field contains mapping name and operator, the operator would be used when executing metadata filter query\n",
123131
"# })"
124-
],
125-
"metadata": {
126-
"collapsed": false,
127-
"pycharm": {
128-
"name": "#%%\n"
129-
}
130-
},
131-
"execution_count": 1,
132-
"outputs": [
133-
{
134-
"ename": "NameError",
135-
"evalue": "name 'AlibabaCloudOpenSearchSettings' is not defined",
136-
"output_type": "error",
137-
"traceback": [
138-
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
139-
"\u001B[0;31mNameError\u001B[0m Traceback (most recent call last)",
140-
"Cell \u001B[0;32mIn[1], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m settings \u001B[38;5;241m=\u001B[39m \u001B[43mAlibabaCloudOpenSearchSettings\u001B[49m(\n\u001B[1;32m 2\u001B[0m endpoint\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe endpoint of opensearch instance, You can find it from the console of Alibaba Cloud OpenSearch.\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 3\u001B[0m instance_id\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe identify of opensearch instance, You can find it from the console of Alibaba Cloud OpenSearch.\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 4\u001B[0m datasource_name\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe name of the data source specified when creating it.\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 5\u001B[0m username\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe username specified when purchasing the instance.\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 6\u001B[0m password\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe password specified when purchasing the instance.\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 7\u001B[0m embedding_index_name\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe name of the vector attribute specified when configuring the instance attributes.\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 8\u001B[0m field_name_mapping\u001B[38;5;241m=\u001B[39m{\n\u001B[1;32m 9\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mid\u001B[39m\u001B[38;5;124m\"\u001B[39m: \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mid\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;66;03m# The id field name map of index document.\u001B[39;00m\n\u001B[1;32m 10\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mdocument\u001B[39m\u001B[38;5;124m\"\u001B[39m: \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mdocument\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;66;03m# The text field name map of index document.\u001B[39;00m\n\u001B[1;32m 11\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124membedding\u001B[39m\u001B[38;5;124m\"\u001B[39m: \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124membedding\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;66;03m# The embedding field name map of index document.\u001B[39;00m\n\u001B[1;32m 12\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmetadata\u001B[39m\u001B[38;5;124m\"\u001B[39m: \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmetadata,=\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;66;03m# The metadata field name map of index document.\u001B[39;00m\n\u001B[1;32m 13\u001B[0m })\n",
141-
"\u001B[0;31mNameError\u001B[0m: name 'AlibabaCloudOpenSearchSettings' is not defined"
142-
]
143-
}
144132
]
145133
},
146134
{
147135
"cell_type": "markdown",
148-
"source": [
149-
"Create an opensearch access instance by settings."
150-
],
151136
"metadata": {
152137
"collapsed": false
153-
}
138+
},
139+
"source": [
140+
"Create an opensearch access instance by settings."
141+
]
154142
},
155143
{
156144
"cell_type": "code",
157145
"execution_count": null,
146+
"metadata": {
147+
"collapsed": false,
148+
"pycharm": {
149+
"name": "#%%\n"
150+
}
151+
},
158152
"outputs": [],
159153
"source": [
160154
"# Create an opensearch instance and index docs.\n",
161155
"opensearch = AlibabaCloudOpenSearch.from_texts(\n",
162156
" texts=docs, embedding=embeddings, config=settings\n",
163157
")"
164-
],
165-
"metadata": {
166-
"collapsed": false,
167-
"pycharm": {
168-
"name": "#%%\n"
169-
}
170-
}
158+
]
171159
},
172160
{
173161
"cell_type": "markdown",
174-
"source": [
175-
"or"
176-
],
177162
"metadata": {
178163
"collapsed": false
179-
}
164+
},
165+
"source": [
166+
"or"
167+
]
180168
},
181169
{
182170
"cell_type": "code",
183171
"execution_count": null,
184-
"outputs": [],
185-
"source": [
186-
"# Create an opensearch instance.\n",
187-
"opensearch = AlibabaCloudOpenSearch(embedding=embeddings, config=settings)"
188-
],
189172
"metadata": {
190173
"collapsed": false,
191174
"pycharm": {
192175
"name": "#%%\n"
193176
}
194-
}
177+
},
178+
"outputs": [],
179+
"source": [
180+
"# Create an opensearch instance.\n",
181+
"opensearch = AlibabaCloudOpenSearch(embedding=embeddings, config=settings)"
182+
]
195183
},
196184
{
197185
"cell_type": "markdown",
198-
"source": [
199-
"Add texts and build index."
200-
],
201186
"metadata": {
202187
"collapsed": false
203-
}
188+
},
189+
"source": [
190+
"Add texts and build index."
191+
]
204192
},
205193
{
206194
"cell_type": "code",
207195
"execution_count": null,
208-
"outputs": [],
209-
"source": [
210-
"metadatas = {\"md_key_a\": \"md_val_a\", \"md_key_b\": \"md_val_b\"}\n",
211-
"# the key of metadatas must match field_name_mapping in settings.\n",
212-
"opensearch.add_texts(texts=docs, ids=[], metadatas=metadatas)"
213-
],
214196
"metadata": {
215197
"collapsed": false,
216198
"pycharm": {
217199
"name": "#%%\n"
218200
}
219-
}
201+
},
202+
"outputs": [],
203+
"source": [
204+
"metadatas = {\"md_key_a\": \"md_val_a\", \"md_key_b\": \"md_val_b\"}\n",
205+
"# the key of metadatas must match field_name_mapping in settings.\n",
206+
"opensearch.add_texts(texts=docs, ids=[], metadatas=metadatas)"
207+
]
220208
},
221209
{
222210
"cell_type": "markdown",
223-
"source": [
224-
"Query and retrieve data."
225-
],
226211
"metadata": {
227212
"collapsed": false
228-
}
213+
},
214+
"source": [
215+
"Query and retrieve data."
216+
]
229217
},
230218
{
231219
"cell_type": "code",
232220
"execution_count": null,
233-
"outputs": [],
234-
"source": [
235-
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
236-
"docs = opensearch.similarity_search(query)\n",
237-
"print(docs[0].page_content)"
238-
],
239221
"metadata": {
240222
"collapsed": false,
241223
"pycharm": {
242224
"name": "#%%\n"
243225
}
244-
}
226+
},
227+
"outputs": [],
228+
"source": [
229+
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
230+
"docs = opensearch.similarity_search(query)\n",
231+
"print(docs[0].page_content)"
232+
]
245233
},
246234
{
247235
"cell_type": "markdown",
248-
"source": [
249-
"Query and retrieve data with metadata\n"
250-
],
251236
"metadata": {
252237
"collapsed": false
253-
}
238+
},
239+
"source": [
240+
"Query and retrieve data with metadata\n"
241+
]
254242
},
255243
{
256244
"cell_type": "code",
257245
"execution_count": null,
246+
"metadata": {
247+
"collapsed": false,
248+
"pycharm": {
249+
"name": "#%%\n"
250+
}
251+
},
258252
"outputs": [],
259253
"source": [
260254
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
261255
"metadatas = {\"md_key_a\": \"md_val_a\"}\n",
262256
"docs = opensearch.similarity_search(query, filter=metadatas)\n",
263257
"print(docs[0].page_content)"
264-
],
265-
"metadata": {
266-
"collapsed": false,
267-
"pycharm": {
268-
"name": "#%%\n"
269-
}
270-
}
258+
]
271259
},
272260
{
273261
"cell_type": "markdown",
274-
"source": [
275-
"If you encounter any problems during use, please feel free to contact <[email protected]>, and we will do our best to provide you with assistance and support.\n"
276-
],
277262
"metadata": {
278263
"collapsed": false,
279264
"pycharm": {
280265
"name": "#%% md\n"
281266
}
282-
}
267+
},
268+
"source": [
269+
"If you encounter any problems during use, please feel free to contact <[email protected]>, and we will do our best to provide you with assistance and support.\n"
270+
]
283271
}
284272
],
285273
"metadata": {
@@ -303,4 +291,4 @@
303291
},
304292
"nbformat": 4,
305293
"nbformat_minor": 0
306-
}
294+
}

0 commit comments

Comments
 (0)