README.md 722 B

llama_index

LlamaIndex (GPT Index) is a project that provides a central interface to connect your LLM's with external data.

基于openai实现

文档:

https://gpt-index.readthedocs.io/en/latest/

To build a simple vector store index:


pip install llama-index



import os
os.environ["OPENAI_API_KEY"] = 'YOUR_OPENAI_API_KEY'

from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader
documents = SimpleDirectoryReader('data').load_data()
index = GPTSimpleVectorIndex(documents)

To save to and load from disk:

# save to disk
index.save_to_disk('index.json')
# load from disk
index = GPTSimpleVectorIndex.load_from_disk('index.json')

To query:

index.query("<question_text>?")