Amazon Neptune - Neptune Analytics 向量存储¶
如果您在 colab 上打开此 Notebook,您可能需要安装 LlamaIndex 🦙。
In [ ]
已复制!
%pip install llama-index-vector-stores-neptune
%pip install llama-index-vector-stores-neptune
初始化 Neptune Analytics 向量包装器¶
In [ ]
已复制!
from llama_index.vector_stores.neptune import NeptuneAnalyticsVectorStore
graph_identifier = ""
embed_dim = 1536
neptune_vector_store = NeptuneAnalyticsVectorStore(
graph_identifier=graph_identifier, embedding_dimension=1536
)
from llama_index.vector_stores.neptune import NeptuneAnalyticsVectorStore graph_identifier = "" embed_dim = 1536 neptune_vector_store = NeptuneAnalyticsVectorStore( graph_identifier=graph_identifier, embedding_dimension=1536 )
加载文档,构建 VectorStoreIndex¶
In [ ]
已复制!
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from IPython.display import Markdown, display
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader from IPython.display import Markdown, display
下载数据
In [ ]
已复制!
!mkdir -p 'data/paul_graham/'
!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'
!mkdir -p 'data/paul_graham/' !wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'
In [ ]
已复制!
# load documents
documents = SimpleDirectoryReader("./data/paul_graham").load_data()
# 加载文档 documents = SimpleDirectoryReader("./data/paul_graham").load_data()
In [ ]
已复制!
from llama_index.core import StorageContext
storage_context = StorageContext.from_defaults(
vector_store=neptune_vector_store
)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context
)
from llama_index.core import StorageContext storage_context = StorageContext.from_defaults( vector_store=neptune_vector_store ) index = VectorStoreIndex.from_documents( documents, storage_context=storage_context )
In [ ]
已复制!
query_engine = index.as_query_engine()
response = query_engine.query("What happened at interleaf?")
display(Markdown(f"<b>{response}</b>"))
query_engine = index.as_query_engine() response = query_engine.query("What happened at interleaf?") display(Markdown(f"{response}"))