Skip to content

Commit

Permalink
docs: added vector store initialization from documents (#196)
Browse files Browse the repository at this point in the history
* feat: added vector store initialization from documents

* nit: fix pr comments

* chore: pr comments

* chore: fix PR comments

* chore: pr comments

---------

Co-authored-by: Averi Kitsch <akitsch@google.com>
  • Loading branch information
vishwarajanand and averikitsch authored Aug 2, 2024
1 parent dd91d54 commit 823821c
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion docs/vector_store.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,49 @@
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Initialize Vector Store with documents\n",
"\n",
"This is a great way to get started quickly. However, the default method is recommended for most applications to avoid accidentally adding duplicate documents."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain_core.documents import Document\n",
"import uuid\n",
"\n",
"docs = [\n",
" Document(\n",
" page_content=\"Red Apple\",\n",
" metadata={\"description\": \"red\", \"content\": \"1\", \"category\": \"fruit\"},\n",
" ),\n",
" Document(\n",
" page_content=\"Banana Cavendish\",\n",
" metadata={\"description\": \"yellow\", \"content\": \"2\", \"category\": \"fruit\"},\n",
" ),\n",
" Document(\n",
" page_content=\"Orange Navel\",\n",
" metadata={\"description\": \"orange\", \"content\": \"3\", \"category\": \"fruit\"},\n",
" ),\n",
"]\n",
"ids = [str(uuid.uuid4()) for i in range(len(docs))]\n",
"\n",
"store_with_documents = await AlloyDBVectorStore.afrom_documents(\n",
" documents=docs,\n",
" ids=ids,\n",
" engine=engine,\n",
" table_name=TABLE_NAME,\n",
" embedding_service=embedding,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -553,7 +596,7 @@
"all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n",
"metadatas = [{\"len\": len(t)} for t in all_texts]\n",
"ids = [str(uuid.uuid4()) for _ in all_texts]\n",
"await store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)\n",
"await custom_store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)\n",
"\n",
"# Use filter on search\n",
"docs = await custom_store.asimilarity_search(query, filter=\"len >= 6\")\n",
Expand Down

0 comments on commit 823821c

Please sign in to comment.