|
88 | 88 | { |
89 | 89 | "data": { |
90 | 90 | "text/plain": [ |
91 | | - "[-0.001046799123287201,\n", |
92 | | - " -0.0031105349771678448,\n", |
93 | | - " 0.0024228920228779316,\n", |
94 | | - " -0.004480978474020958,\n", |
95 | | - " -0.010343699716031551,\n", |
96 | | - " 0.012758520431816578,\n", |
97 | | - " -0.00535263866186142,\n", |
98 | | - " -0.003002384677529335,\n", |
99 | | - " -0.007115328684449196,\n", |
100 | | - " -0.03378167003393173]" |
| 91 | + "[-0.001025049015879631,\n", |
| 92 | + " -0.0030993607360869646,\n", |
| 93 | + " 0.0024536605924367905,\n", |
| 94 | + " -0.004484387580305338,\n", |
| 95 | + " -0.010331203229725361,\n", |
| 96 | + " 0.012700922787189484,\n", |
| 97 | + " -0.005368996877223253,\n", |
| 98 | + " -0.0029411641880869865,\n", |
| 99 | + " -0.0070833307690918446,\n", |
| 100 | + " -0.03386051580309868]" |
101 | 101 | ] |
102 | 102 | }, |
103 | 103 | "execution_count": 3, |
|
127 | 127 | { |
128 | 128 | "data": { |
129 | 129 | "text/plain": [ |
130 | | - "[-0.017399806529283524,\n", |
131 | | - " -2.3427608653037169e-07,\n", |
132 | | - " 0.0014656063867732882,\n", |
133 | | - " -0.02562308870255947,\n", |
134 | | - " -0.019890939816832542,\n", |
135 | | - " 0.016027139499783516,\n", |
136 | | - " -0.0036763285752385855,\n", |
137 | | - " 0.0008253469131886959,\n", |
138 | | - " 0.006609130185097456,\n", |
139 | | - " -0.025165533646941185]" |
| 130 | + "[-0.01747742109000683,\n", |
| 131 | + " -5.228330701356754e-05,\n", |
| 132 | + " 0.0013870716793462634,\n", |
| 133 | + " -0.025637786835432053,\n", |
| 134 | + " -0.01985435001552105,\n", |
| 135 | + " 0.016117358580231667,\n", |
| 136 | + " -0.0037306349258869886,\n", |
| 137 | + " 0.0008945261361077428,\n", |
| 138 | + " 0.006577865686267614,\n", |
| 139 | + " -0.025091219693422318]" |
140 | 140 | ] |
141 | 141 | }, |
142 | 142 | "execution_count": 4, |
|
190 | 190 | }, |
191 | 191 | { |
192 | 192 | "cell_type": "code", |
193 | | - "execution_count": null, |
| 193 | + "execution_count": 6, |
194 | 194 | "metadata": {}, |
195 | | - "outputs": [], |
| 195 | + "outputs": [ |
| 196 | + { |
| 197 | + "data": { |
| 198 | + "text/plain": [ |
| 199 | + "[0.00037810884532518685,\n", |
| 200 | + " -0.05080341175198555,\n", |
| 201 | + " -0.03514723479747772,\n", |
| 202 | + " -0.02325104922056198,\n", |
| 203 | + " -0.044158220291137695,\n", |
| 204 | + " 0.020487844944000244,\n", |
| 205 | + " 0.0014617963461205363,\n", |
| 206 | + " 0.031261757016181946,\n", |
| 207 | + " 0.05605152249336243,\n", |
| 208 | + " 0.018815357238054276]" |
| 209 | + ] |
| 210 | + }, |
| 211 | + "execution_count": 6, |
| 212 | + "metadata": {}, |
| 213 | + "output_type": "execute_result" |
| 214 | + } |
| 215 | + ], |
196 | 216 | "source": [ |
197 | 217 | "os.environ[\"TOKENIZERS_PARALLELISM\"] = \"false\"\n", |
198 | 218 | "from redisvl.vectorize.text import HFTextVectorizer\n", |
|
229 | 249 | "pip install google-cloud-aiplatform>=1.26\n", |
230 | 250 | "```\n", |
231 | 251 | "\n", |
232 | | - "1. Then you need to gain access to a [Google Cloud Project](https://cloud.google.com/gcp?hl=en) and provide [access to credentials](https://cloud.google.com/docs/authentication/application-default-credentials). This typically accomplished with the `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to the path of a JSON key file downloaded from your service account on GCP.\n", |
233 | | - "2. Lastly, you need to find your [project ID](https://support.google.com/googleapi/answer/7014113?hl=en) and [geographic region for VertexAI](https://cloud.google.com/vertex-ai/docs/general/locations)." |
| 252 | + "1. Then you need to gain access to a [Google Cloud Project](https://cloud.google.com/gcp?hl=en) and provide [access to credentials](https://cloud.google.com/docs/authentication/application-default-credentials). This is accomplished by setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to the path of a JSON key file downloaded from your service account on GCP.\n", |
| 253 | + "2. Lastly, you need to find your [project ID](https://support.google.com/googleapi/answer/7014113?hl=en) and [geographic region for VertexAI](https://cloud.google.com/vertex-ai/docs/general/locations).\n", |
| 254 | + "\n", |
| 255 | + "\n", |
| 256 | + "**Make sure the following env vars are set:**\n", |
| 257 | + "```\n", |
| 258 | + "GOOGLE_APPLICATION_CREDENTIALS=<path to your gcp JSON creds>\n", |
| 259 | + "GCP_PROJECT_ID=<your gcp project id>\n", |
| 260 | + "GCP_LOCATION=<your gcp geo region for vertex ai>\n", |
| 261 | + "```" |
234 | 262 | ] |
235 | 263 | }, |
236 | 264 | { |
237 | 265 | "cell_type": "code", |
238 | | - "execution_count": null, |
| 266 | + "execution_count": 12, |
239 | 267 | "metadata": {}, |
240 | | - "outputs": [], |
| 268 | + "outputs": [ |
| 269 | + { |
| 270 | + "data": { |
| 271 | + "text/plain": [ |
| 272 | + "[0.04373306408524513,\n", |
| 273 | + " -0.05040992051362991,\n", |
| 274 | + " -0.011946038343012333,\n", |
| 275 | + " -0.043528858572244644,\n", |
| 276 | + " 0.021510830149054527,\n", |
| 277 | + " 0.028604144230484962,\n", |
| 278 | + " 0.014770914800465107,\n", |
| 279 | + " -0.01610461436212063,\n", |
| 280 | + " -0.0036560404114425182,\n", |
| 281 | + " 0.013746795244514942]" |
| 282 | + ] |
| 283 | + }, |
| 284 | + "execution_count": 12, |
| 285 | + "metadata": {}, |
| 286 | + "output_type": "execute_result" |
| 287 | + } |
| 288 | + ], |
241 | 289 | "source": [ |
242 | 290 | "from redisvl.vectorize.text import VertexAITextVectorizer\n", |
243 | 291 | "\n", |
244 | 292 | "\n", |
245 | 293 | "# create a vectorizer\n", |
246 | | - "vtx = VertexAITextVectorizer(\n", |
247 | | - " api_config={\n", |
248 | | - " \"project_id\": os.environ[\"GCP_PROJECT_ID\"],\n", |
249 | | - " \"location\": os.environ[\"GCP_LOCATION\"]\n", |
250 | | - " }\n", |
251 | | - ")\n", |
| 294 | + "vtx = VertexAITextVectorizer()\n", |
252 | 295 | "\n", |
253 | 296 | "# embed a sentence\n", |
254 | 297 | "test = vtx.embed(\"This is a test sentence.\")\n", |
|
287 | 330 | }, |
288 | 331 | { |
289 | 332 | "cell_type": "code", |
290 | | - "execution_count": 8, |
| 333 | + "execution_count": 13, |
291 | 334 | "metadata": {}, |
292 | 335 | "outputs": [], |
293 | 336 | "source": [ |
|
305 | 348 | }, |
306 | 349 | { |
307 | 350 | "cell_type": "code", |
308 | | - "execution_count": 9, |
| 351 | + "execution_count": 14, |
309 | 352 | "metadata": {}, |
310 | 353 | "outputs": [ |
311 | 354 | { |
312 | 355 | "name": "stdout", |
313 | 356 | "output_type": "stream", |
314 | 357 | "text": [ |
315 | | - "\u001b[32m20:13:35\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n", |
316 | | - "\u001b[32m20:13:35\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. providers\n" |
| 358 | + "\u001b[32m22:02:27\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m Indices:\n", |
| 359 | + "\u001b[32m22:02:27\u001b[0m \u001b[34m[RedisVL]\u001b[0m \u001b[1;30mINFO\u001b[0m 1. providers\n" |
317 | 360 | ] |
318 | 361 | } |
319 | 362 | ], |
|
324 | 367 | }, |
325 | 368 | { |
326 | 369 | "cell_type": "code", |
327 | | - "execution_count": 10, |
| 370 | + "execution_count": 15, |
328 | 371 | "metadata": {}, |
329 | 372 | "outputs": [], |
330 | 373 | "source": [ |
|
340 | 383 | }, |
341 | 384 | { |
342 | 385 | "cell_type": "code", |
343 | | - "execution_count": 11, |
| 386 | + "execution_count": 16, |
344 | 387 | "metadata": {}, |
345 | 388 | "outputs": [ |
346 | 389 | { |
347 | 390 | "name": "stdout", |
348 | 391 | "output_type": "stream", |
349 | 392 | "text": [ |
350 | | - "That is a happy dog\n", |
351 | | - "0.160862445831\n", |
352 | | - "That is a happy person\n", |
353 | | - "0.273598074913\n", |
354 | | - "Today is a sunny day\n", |
355 | | - "0.744559526443\n" |
| 393 | + "That is a happy dog 0.160862326622\n", |
| 394 | + "That is a happy person 0.273598492146\n", |
| 395 | + "Today is a sunny day 0.744559407234\n" |
356 | 396 | ] |
357 | 397 | } |
358 | 398 | ], |
|
369 | 409 | " num_results=3\n", |
370 | 410 | ")\n", |
371 | 411 | "\n", |
372 | | - "results = index.search(query.query, query_params=query.params)\n", |
373 | | - "for doc in results.docs:\n", |
374 | | - " print(doc.text)\n", |
375 | | - " print(doc.vector_distance)" |
| 412 | + "results = index.query(query)\n", |
| 413 | + "for doc in results:\n", |
| 414 | + " print(doc[\"text\"], doc[\"vector_distance\"])" |
376 | 415 | ] |
377 | 416 | } |
378 | 417 | ], |
|
0 commit comments