-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
''' | ||
This script creates a vector database from texts with | ||
llama_index. | ||
''' | ||
import logging | ||
import sys | ||
from llama_index import ( | ||
GPTSimpleVectorIndex, | ||
GPTSimpleKeywordTableIndex, | ||
GPTListIndex, | ||
SimpleDirectoryReader | ||
) | ||
|
||
# Setup logging and configure basics | ||
logging.basicConfig(stream=sys.stdout, level=logging.INFO) | ||
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout)) | ||
|
||
|
||
# Data set load and create if not exists | ||
db_index = None | ||
if (not os.path.exists('trainingdata/sesa.json')): | ||
logging.info('Creating database...') | ||
db_documents = SimpleDirectoryReader('trainingdata/sesa').load_data() | ||
db_index = GPTSimpleVectorIndex.from_documents(db_documents) | ||
db_index.save_to_disk('trainingdata/sesa.json') | ||
|
||
if (db_index is None): | ||
logging.info('Loading database...') | ||
db_index = GPTSimpleVectorIndex.('trainingdata/sesa.json') |