Skip to content

Commit

Permalink
Update DynamoDBDocstoreDemo notebook description (#6974)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwuiwon committed Jul 20, 2023
1 parent 2ab57dc commit 7e39484
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions docs/examples/docstore/DynamoDBDocstoreDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "1d12d766-3ca8-4012-9da2-248be80bb6ab",
"metadata": {
"tags": []
Expand All @@ -43,11 +43,9 @@
"from llama_index import (\n",
" SimpleDirectoryReader,\n",
" ServiceContext,\n",
" LLMPredictor,\n",
" StorageContext,\n",
")\n",
"from llama_index import VectorStoreIndex, ListIndex, SimpleKeywordTableIndex\n",
"from llama_index.composability import ComposableGraph\n",
"from llama_index.llms import OpenAI\n",
"from llama_index.response.notebook_utils import display_response"
]
Expand All @@ -63,7 +61,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"id": "e7cdaf9d-cfbd-4ced-8d4e-6eef8508224d",
"metadata": {
"tags": []
Expand All @@ -85,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "f97e558a-c29f-44ec-ab33-1f481da1a6ef",
"metadata": {
"tags": []
Expand Down Expand Up @@ -118,13 +116,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "54b9bd36",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.storage.docstore.dynamodb_docstore import DynamoDBDocumentStore\n",
"from llama_index.storage.index_store.dynamodb_index_store import DynamoDBIndexStore"
"from llama_index.storage.index_store.dynamodb_index_store import DynamoDBIndexStore\n",
"from llama_index.vector_stores.dynamodb import DynamoDBVectorStore"
]
},
{
Expand All @@ -139,6 +138,7 @@
"storage_context = StorageContext.from_defaults(\n",
" docstore=DynamoDBDocumentStore.from_table_name(table_name=TABLE_NAME),\n",
" index_store=DynamoDBIndexStore.from_table_name(table_name=TABLE_NAME),\n",
" vector_store=DynamoDBVectorStore.from_table_name(table_name=TABLE_NAME),\n",
")"
]
},
Expand All @@ -160,7 +160,7 @@
"id": "528149c1-5bde-4eba-b75a-e8fa1da17d7c",
"metadata": {},
"source": [
"#### Define Multiple Indexes\n",
"#### Define & Add Multiple Indexes\n",
"\n",
"Each index uses the same underlying Node."
]
Expand All @@ -174,6 +174,7 @@
},
"outputs": [],
"source": [
"# https://gpt-index.readthedocs.io/en/latest/api_reference/indices/list.html\n",
"list_index = ListIndex(nodes, storage_context=storage_context)"
]
},
Expand All @@ -186,6 +187,7 @@
},
"outputs": [],
"source": [
"# https://gpt-index.readthedocs.io/en/latest/api_reference/indices/vector_store.html\n",
"vector_index = VectorStoreIndex(nodes, storage_context=storage_context)"
]
},
Expand All @@ -198,6 +200,7 @@
},
"outputs": [],
"source": [
"# https://gpt-index.readthedocs.io/en/latest/api_reference/indices/table.html\n",
"keyword_table_index = SimpleKeywordTableIndex(nodes, storage_context=storage_context)"
]
},
Expand Down Expand Up @@ -234,8 +237,8 @@
},
"outputs": [],
"source": [
"# NOTE: docstore and index_store is persisted in DynamoDB by default\n",
"# NOTE: here only need to persist simple vector store to dick\n",
"# NOTE: docstore, index_store, and vector_index is persisted in DynamoDB by default when they are created\n",
"# NOTE: You can also persist simple vector store to disk by using the command below\n",
"storage_context.persist()"
]
},
Expand Down Expand Up @@ -269,14 +272,17 @@
"storage_context = StorageContext.from_defaults(\n",
" docstore=DynamoDBDocumentStore.from_table_name(table_name=TABLE_NAME),\n",
" index_store=DynamoDBIndexStore.from_table_name(table_name=TABLE_NAME),\n",
" vector_store=DynamoDBVectorStore.from_table_name(table_name=TABLE_NAME),\n",
")\n",
"\n",
"list_index = load_index_from_storage(storage_context=storage_context, index_id=list_id)\n",
"vector_index = load_index_from_storage(\n",
" storage_context=storage_context, index_id=vector_id\n",
")\n",
"keyword_table_index = load_index_from_storage(\n",
" storage_context=storage_context, index_id=keyword_id\n",
")\n",
"\n",
"# You need to add \"vector_store=DynamoDBVectorStore.from_table_name(table_name=TABLE_NAME)\" to StorageContext to load vector index from DynamoDB\n",
"vector_index = load_index_from_storage(\n",
" storage_context=storage_context, index_id=vector_id\n",
")"
]
},
Expand Down Expand Up @@ -382,9 +388,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "llama_index",
"display_name": "strat",
"language": "python",
"name": "llama_index"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -396,7 +402,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 7e39484

Please sign in to comment.