|
191 | 191 | }, |
192 | 192 | "outputs": [], |
193 | 193 | "source": [ |
194 | | - "import chromadb\n" |
| 194 | + "import chromadb" |
195 | 195 | ] |
196 | 196 | }, |
197 | 197 | { |
|
200 | 200 | "metadata": {}, |
201 | 201 | "outputs": [], |
202 | 202 | "source": [ |
203 | | - "\n", |
204 | 203 | "# setup Chroma in-memory, for easy prototyping. Can add persistence easily!\n", |
205 | | - "client = chromadb.PersistentClient()\n" |
| 204 | + "client = chromadb.PersistentClient()" |
206 | 205 | ] |
207 | 206 | }, |
208 | 207 | { |
|
247 | 246 | } |
248 | 247 | ], |
249 | 248 | "source": [ |
250 | | - "\n", |
251 | 249 | "# Create collection. get_collection, get_or_create_collection, delete_collection also available!\n", |
252 | 250 | "collection2 = client.get_or_create_collection(\"test\")\n", |
253 | 251 | "\n", |
254 | 252 | "# Add docs to the collection. Can also update and delete. Row-based API coming soon!\n", |
255 | 253 | "collection2.add(\n", |
256 | | - " documents=[\"This is document1\", \"This is document2\"], # we handle tokenization, embedding, and indexing automatically. You can skip that and add your own embeddings as well\n", |
257 | | - " metadatas=[{\"source\": \"notion\"}, {\"source\": \"google-docs\"}], # filter on these!\n", |
258 | | - " ids=[\"doc1\", \"doc2\"], # unique for each doc\n", |
259 | | - " embeddings=[[1,2,3], [4,5,6]] # optional, we can also embed for you\n", |
| 254 | + " documents=[\n", |
| 255 | + " \"This is document1\",\n", |
| 256 | + " \"This is document2\",\n", |
| 257 | + " ], # we handle tokenization, embedding, and indexing automatically. You can skip that and add your own embeddings as well\n", |
| 258 | + " metadatas=[{\"source\": \"notion\"}, {\"source\": \"google-docs\"}], # filter on these!\n", |
| 259 | + " ids=[\"doc1\", \"doc2\"], # unique for each doc\n", |
| 260 | + " embeddings=[[1, 2, 3], [4, 5, 6]], # optional, we can also embed for you\n", |
260 | 261 | ")\n", |
261 | 262 | "\n", |
262 | 263 | "# Query/search 2 most similar results. You can also .get by id\n", |
263 | 264 | "results = collection2.query(\n", |
264 | | - " query_embeddings=[[1,2,3]],\n", |
| 265 | + " query_embeddings=[[1, 2, 3]],\n", |
265 | 266 | " n_results=2,\n", |
266 | 267 | " # where={\"metadata_field\": \"is_equal_to_this\"}, # optional filter\n", |
267 | 268 | " # where_document={\"$contains\":\"search_string\"} # optional filter\n", |
|
304 | 305 | }, |
305 | 306 | "outputs": [], |
306 | 307 | "source": [ |
307 | | - "coll=client.get_collection(\"test\")" |
| 308 | + "coll = client.get_collection(\"test\")" |
308 | 309 | ] |
309 | 310 | }, |
310 | 311 | { |
|
335 | 336 | "metadata": {}, |
336 | 337 | "outputs": [], |
337 | 338 | "source": [ |
338 | | - "client.delete_collection(\"test\") # delete collection" |
| 339 | + "client.delete_collection(\"test\") # delete collection" |
339 | 340 | ] |
340 | 341 | }, |
341 | 342 | { |
|
357 | 358 | } |
358 | 359 | ], |
359 | 360 | "source": [ |
360 | | - "client.list_collections() # list collections" |
| 361 | + "client.list_collections() # list collections" |
361 | 362 | ] |
362 | 363 | }, |
363 | 364 | { |
|
399 | 400 | "metadata": {}, |
400 | 401 | "outputs": [], |
401 | 402 | "source": [ |
402 | | - "pclient = chromadb.PersistentClient(\"~/.chroma4\") # persistent client\n", |
| 403 | + "pclient = chromadb.PersistentClient(\"~/.chroma4\") # persistent client\n", |
403 | 404 | "\n", |
404 | 405 | "pcol = pclient.create_collection(\"test3\")" |
405 | 406 | ] |
|
414 | 415 | " documents=[\"This is document1\", \"This is document2\"],\n", |
415 | 416 | " metadatas=[{\"source\": \"notion\"}, {\"source\": \"google-docs\"}],\n", |
416 | 417 | " ids=[\"doc1\", \"doc2\"],\n", |
417 | | - " embeddings=[[1,2,3], [4,5,6]]\n", |
418 | | - ")\n" |
| 418 | + " embeddings=[[1, 2, 3], [4, 5, 6]],\n", |
| 419 | + ")" |
419 | 420 | ] |
420 | 421 | }, |
421 | 422 | { |
|
479 | 480 | }, |
480 | 481 | "outputs": [], |
481 | 482 | "source": [ |
482 | | - "client2= chromadb.PersistentClient(\"/Users/dhruvanand/Code/vector-io/src/vdf_io/notebooks/chroma\")\n" |
| 483 | + "client2 = chromadb.PersistentClient(\n", |
| 484 | + " \"/Users/dhruvanand/Code/vector-io/src/vdf_io/notebooks/chroma\"\n", |
| 485 | + ")" |
483 | 486 | ] |
484 | 487 | }, |
485 | 488 | { |
|
559 | 562 | }, |
560 | 563 | "outputs": [], |
561 | 564 | "source": [ |
562 | | - "coll2=client2.get_collection(\"vdf_2024_9-11\")" |
| 565 | + "coll2 = client2.get_collection(\"vdf_2024_9-11\")" |
563 | 566 | ] |
564 | 567 | }, |
565 | 568 | { |
|
653 | 656 | " documents=[\"This is document1\", \"This is document2\"],\n", |
654 | 657 | " metadatas=[{\"source\": \"notion\"}, {\"source\": \"google-docs\"}],\n", |
655 | 658 | " ids=[\"doc5\", \"doc6\"],\n", |
656 | | - " embeddings=[[1,2,3], None]\n", |
| 659 | + " embeddings=[[1, 2, 3], None],\n", |
657 | 660 | ")" |
658 | 661 | ] |
659 | 662 | }, |
|
0 commit comments