gpt memory
1.0.0
LocalFilesystemMemory 是 Llama Index 的 GPTSimpleVectorIndex 之上的一層,它抽象化了管理磁碟上保存的索引的詳細資訊。它假設 / 建立一個用於儲存索引的目錄結構,並提供一個簡單的介面來管理它們。
您可以在此儲存庫中找到使用一些維基百科檔案的範例:
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 ))
返回: 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)
:提出問題的主要入口點。memory.create_index(name, docs, description=None)
:建立索引的主要方式。文件可以是字串、字串清單或 GPTIndex 的 Document 物件清單。memory.update_index(name, docs)
:用新文件更新索引。memory.delete_index(name)
:刪除索引。在幕後,這些函數使用:
memory.get_index(name)
memory.query_index(name, prompt)
memory.find_most_relevant_index(prompt)
在底層,目錄結構如下:
- index_folder/
- metadata.json
- indexes/
- index_1.json
- index_2.json
- ...
metadata.json 檔案包含以下資訊:
{
"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.",
},
]
}