LocalFilesystemMemory adalah lapisan di atas GPTSimpleVectorIndex Indeks Llama yang mengabstraksi rincian pengelolaan indeks yang disimpan di disk. Ini mengasumsikan/membuat struktur direktori untuk menyimpan indeks dan menyediakan antarmuka sederhana untuk mengelolanya.
Contoh penggunaan beberapa file Wikipedia dapat Anda temukan di repo ini:
from llama_index import SimpleDirectoryReader
from gpt_memory import LocalFilesystemMemory
phil = SimpleDirectoryReader ( "gpt_memory/examples/phil" )
animals = SimpleDirectoryReader ( "gpt_memory/examples/animals" )
phil_docs = phil . load_data ()
animal_docs = animals . load_data ()
memory = LocalFilesystemMemory ( "example" )
memory . create_index ( "phil" , phil_docs )
memory . create_index ( "animals" , animal_docs )
query = "What is a capybara?"
print ( memory . query ( query ))
Kembali: A capybara is a giant cavy rodent native to South America, which is the largest living rodent and a member of the genus Hydrochoerus. It inhabits savannas and dense forests, lives near bodies of water, and is a highly social species that can be found in groups as large as 100 individuals. The capybara is hunted for its meat and hide and also for grease from its thick fatty skin, but it is not considered a threatened species.
memory.query(prompt)
: Titik masuk utama untuk mengajukan pertanyaan.memory.create_index(name, docs, description=None)
: Cara utama untuk membuat indeks. Dokumen dapat berupa string, daftar string, atau daftar objek Dokumen GPTIndex.memory.update_index(name, docs)
: Perbarui indeks dengan dokumen baru.memory.delete_index(name)
: Menghapus indeks.Di bawah tenda, fungsi-fungsi tersebut menggunakan:
memory.get_index(name)
memory.query_index(name, prompt)
memory.find_most_relevant_index(prompt)
Di bawah tenda, struktur direktorinya adalah sebagai berikut:
- index_folder/
- metadata.json
- indexes/
- index_1.json
- index_2.json
- ...
File metadata.json berisi informasi berikut:
{
"index_count": 2,
"index_descriptions": [
{
"name": "index_1",
"description": "Description of index generated by GPT Index.",
},
{
"name": "index_2",
"description": "Description of index generated by GPT Index.",
},
]
}