Amazon Neptune - Neptune Analytics vector store

Amazon Neptune - Neptune Analytics vector store

Amazon Neptune Analytics를 LlamaIndex 벡터 스토어로 사용해 문서를 인덱싱하고 질의하는 예시예요. NeptuneAnalyticsVectorStore로 래퍼를 초기화하고 VectorStoreIndex를 만드는 흐름을 볼게요.

출처: 문서

본문

이 노트북을 colab에서 여는 경우 LlamaIndex 🦙를 설치해야 할 수 있습니다.

%pip install llama-index-vector-stores-neptune

Neptune Analytics 벡터 래퍼 초기화

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 구축

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from IPython.display import Markdown, display

데이터 다운로드

!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'
# load documents
documents = SimpleDirectoryReader("./data/paul_graham").load_data()
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
)
query_engine = index.as_query_engine()
response = query_engine.query("What happened at interleaf?")
display(Markdown(f"<b>{response}</b>"))

NeptuneAnalyticsVectorStore에 graph_identifier(Neptune Analytics 그래프 식별자)와 embedding_dimension(임베딩 차원)을 전달해 래퍼를 만들고, 이를 StorageContext의 vector_store로 지정해 VectorStoreIndex.from_documents를 호출하면 문서들이 Neptune Analytics 그래프에 벡터로 저장됩니다. 이후 as_query_engine()으로 질의하면 됩니다.

더 알아보기 (Learn more)