■ VectorStoreIndex 클래스의 storage_context 변수를 사용해 라마 인덱스 데이터를 저장하는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import os import logging import sys from llama_index.core import SimpleDirectoryReader, GPTVectorStoreIndex os.environ["OPENAI_API_KEY"] = "<OPENAI_API_KEY>" logging.basicConfig(stream = sys.stdout, level = logging.DEBUG, force = True) simpleDirectoryReader = SimpleDirectoryReader(input_dir = "/home/king/data") documentList = simpleDirectoryReader.load_data() vectorStoreIndex = GPTVectorStoreIndex.from_documents(documentList, model = "gpt-3.5-instruct") vectorStoreIndex.storage_context.persist() |
※ 실행 디렉토리에서 storage 디렉토리가 생성되고 인덱스 데이터가 저장된다.
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
aiohttp==3.9.5 aiosignal==1.3.1 async-timeout==4.0.3 attrs==23.2.0 certifi==2024.6.2 charset-normalizer==3.3.2 dataclasses-json==0.5.14 frozenlist==1.4.1 fsspec==2024.6.0 greenlet==3.0.3 idna==3.7 langchain==0.0.181 llama-index==0.6.12 marshmallow==3.21.3 multidict==6.0.5 mypy-extensions==1.0.0 numexpr==2.10.0 numpy==1.26.4 openai==0.28.0 openapi-schema-pydantic==1.2.4 packaging==24.0 pandas==2.2.2 pydantic==1.10.15 python-dateutil==2.9.0.post0 pytz==2024.1 PyYAML==6.0.1 regex==2024.5.15 requests==2.32.3 six==1.16.0 SQLAlchemy==2.0.24 tenacity==8.3.0 tiktoken==0.7.0 tqdm==4.66.4 typing-inspect==0.8.0 typing_extensions==4.5.0 tzdata==2024.1 urllib3==1.26.18 yarl==1.9.4 |
※ pip install llama-index 명령을 실행했다.