-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_obsidian_index.py
31 lines (20 loc) · 1010 Bytes
/
create_obsidian_index.py
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
""" Functions used to index and store documents and other context for later querying using ChatGPT """
from llama_index import download_loader, GPTSimpleVectorIndex
def create_obsidian_index(location: str, index_name: str) -> None:
"""
Create an GPTSimpleVectorIndex from an Obsidian Database
:param location: The location of the root of the Obsidian archive
:param index_name: The name of the index file to generate
"""
obsidian_reader = download_loader("ObsidianReader")
# obsidian_reader is a class-like function, and it takes arguments built dynamically from the download_loader
# method above.
# noinspection PyArgumentList
documents = obsidian_reader(location).load_data()
index = GPTSimpleVectorIndex(documents)
index.save_to_disk(index_name)
if __name__ == "__main__":
import sys
PATH = "/home/john/Base/" if not sys.argv[1] else sys.argv[1]
print("This will take some time")
create_obsidian_index(PATH, "obsidian_index.json")