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.",
},
]
}