a0c8464e58
Build Package / build (ubuntu-latest) (push) Failing after 1s
CodeQL / Analyze (python) (push) Failing after 1s
Core Typecheck / core-typecheck (push) Failing after 1s
Linting / lint (push) Failing after 1s
llama-dev tests / test-llama-dev (push) Failing after 1s
Publish Sub-Package to PyPI if Needed / publish_subpackage_if_needed (push) Has been skipped
Sync Docs to Developer Hub / sync-docs (push) Failing after 0s
Build Package / build (windows-latest) (push) Has been cancelled
102 lines
2.5 KiB
Plaintext
102 lines
2.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"%pip install llama-index\n",
|
|
"%pip install llama-index-vector-stores-awsdocdb"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymongo\n",
|
|
"from llama_index.vector_stores.awsdocdb import AWSDocDbVectorStore\n",
|
|
"from llama_index.core import VectorStoreIndex\n",
|
|
"from llama_index.core import StorageContext\n",
|
|
"from llama_index.core import SimpleDirectoryReader\n",
|
|
"import os"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"!mkdir -p 'data/10k/'\n",
|
|
"!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/10k/uber_2021.pdf' -O 'data/10k/uber_2021.pdf'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"mongo_uri = os.environ[\"MONGO_URI\"]\n",
|
|
"mongodb_client = pymongo.MongoClient(mongo_uri)\n",
|
|
"store = AWSDocDbVectorStore(mongodb_client)\n",
|
|
"storage_context = StorageContext.from_defaults(vector_store=store)\n",
|
|
"uber_docs = SimpleDirectoryReader(\n",
|
|
" input_files=[\"./data/10k/uber_2021.pdf\"]\n",
|
|
").load_data()\n",
|
|
"index = VectorStoreIndex.from_documents(\n",
|
|
" uber_docs, storage_context=storage_context\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"response = index.as_query_engine().query(\"What was Uber's revenue?\")\n",
|
|
"display(f\"{response}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from llama_index.core import Response\n",
|
|
"\n",
|
|
"print(store._collection.count_documents({}))\n",
|
|
"typed_response = (\n",
|
|
" response if isinstance(response, Response) else response.get_response()\n",
|
|
")\n",
|
|
"ref_doc_id = typed_response.source_nodes[0].node.ref_doc_id\n",
|
|
"print(store._collection.count_documents({\"metadata.ref_doc_id\": ref_doc_id}))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Test delete\n",
|
|
"if ref_doc_id:\n",
|
|
" store.delete(ref_doc_id)\n",
|
|
" print(store._collection.count_documents({}))"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"language_info": {
|
|
"name": "python"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|