Skip to content

Commit 1291ee8

Browse files
authored
Merge pull request #250 from transformerlab/fix/rag-reindex
Fix RAG Reindexing and install the plugin if not already installed
2 parents 4873bc6 + 8791699 commit 1291ee8

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

transformerlab/plugins/generate_rag_outputs/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async def run_evaluation():
137137
plugin = experiment_config.get("rag_engine")
138138
if plugin is None or plugin == "":
139139
raise ValueError(
140-
"No RAG engine has been assigned to this experiment. Please install a RAG plugin from the Plugins Tab."
140+
"No RAG engine has been assigned to this experiment. Please install a RAG plugin from the Plugins Tab and set it by going to the Interact tab."
141141
)
142142

143143
# Set up RAG settings

transformerlab/plugins/llamaindex_simple_document_search/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"plugin-format": "python",
66
"type": "rag",
7-
"version": "0.0.8",
7+
"version": "0.0.9",
88
"model_architectures": [],
99
"supported_hardware_architectures": [
1010
"cpu",

transformerlab/plugins/llamaindex_simple_document_search/main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,26 @@ def main():
4646

4747
args, unknown = parser.parse_known_args()
4848

49+
continue_after_index = False
50+
4951
documents_dir = args.documents_dir
5052
persistency_dir = os.path.join(documents_dir, "persist")
5153

54+
if not os.path.exists(persistency_dir) and not args.index:
55+
sys.stderr.write("Documents have not been indexed. Indexing them first")
56+
args.index = True
57+
continue_after_index = True
58+
5259
if args.index:
5360
start_time = time.time()
5461
index_documents(documents_dir, persistency_dir, args.embedding_model)
5562
elapsed_time = time.time() - start_time
5663

5764
result = {"status": "success", "elapsed_time": elapsed_time}
58-
print(json.dumps(result))
59-
return
65+
sys.stderr.write(json.dumps(result))
66+
if not continue_after_index:
67+
sys.stderr.write("Indexing complete. Exiting.")
68+
return
6069

6170
# SETTINGS
6271
number_of_search_results = 2

transformerlab/routers/experiment/rag.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ class EmbedRequest(BaseModel):
2121
@router.get("/query")
2222
async def query(experimentId: str, query: str, settings: str = None, rag_folder: str = "rag"):
2323
"""Query the RAG engine"""
24+
2425
experiment_dir = await dirs.experiment_dir_by_id(experimentId)
2526
documents_dir = os.path.join(experiment_dir, "documents")
2627
documents_dir = os.path.join(documents_dir, rag_folder)
28+
documents_dir = os.path.abspath(documents_dir)
29+
if not documents_dir.startswith(os.path.abspath(experiment_dir)):
30+
return "Error: Invalid RAG folder path"
2731
if not os.path.exists(documents_dir):
2832
return "Error: The RAG folder does not exist in the documents directory"
2933
experiment_details = await db.experiment_get(id=experimentId)
@@ -75,6 +79,7 @@ async def query(experimentId: str, query: str, settings: str = None, rag_folder:
7579
"--settings",
7680
settings,
7781
]
82+
7883
print(f"Calling plugin {plugin_path}" + " with model " + model + " and query " + query)
7984
venv_path = os.path.join(plugin_path, "venv")
8085
if os.path.exists(venv_path) and os.path.isdir(venv_path):
@@ -113,6 +118,7 @@ async def query(experimentId: str, query: str, settings: str = None, rag_folder:
113118
@router.get("/reindex")
114119
async def reindex(experimentId: str, rag_folder: str = "rag"):
115120
"""Reindex the RAG engine"""
121+
116122
experiment_dir = await dirs.experiment_dir_by_id(experimentId)
117123
documents_dir = os.path.join(experiment_dir, "documents")
118124
documents_dir = os.path.join(documents_dir, rag_folder)

0 commit comments

Comments
 (0)