pvanand commited on
Commit
aceb069
·
verified ·
1 Parent(s): b8e46cf

Update rag_routerv2.py

Browse files
Files changed (1) hide show
  1. rag_routerv2.py +22 -20
rag_routerv2.py CHANGED
@@ -81,26 +81,6 @@ async def create_embedding_table(
81
  with open(file_path, "wb") as buffer:
82
  shutil.copyfileobj(file.file, buffer)
83
 
84
- # Store user_id and table_name in a JSON file
85
- try:
86
- tables_file_path = './data/tables.json'
87
- os.makedirs(os.path.dirname(tables_file_path), exist_ok=True)
88
- # Load existing tables or create a new file if it doesn't exist
89
- try:
90
- with open(tables_file_path, 'r') as f:
91
- tables = json.load(f)
92
- except (FileNotFoundError, json.JSONDecodeError):
93
- tables = {}
94
-
95
- # Update the tables dictionary
96
- if user_id not in tables:
97
- tables[user_id] = []
98
- if table_id not in [table['table_id'] for table in tables[user_id]]:
99
- tables[user_id].append({"table_id": table_id, "table_name": table_name})
100
-
101
- # Write the updated tables back to the JSON file
102
- with open(tables_file_path, 'w') as f:
103
- json.dump(tables, f)
104
 
105
  except Exception as e:
106
  raise HTTPException(status_code=500, detail=f"Failed to update tables file: {str(e)}")
@@ -123,6 +103,28 @@ async def create_embedding_table(
123
  )
124
  index.storage_context.persist(persist_dir=f"./lancedb/index/{table_id}")
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  return CreateTableResponse(
127
  table_id=table_id,
128
  message="Table created and documents indexed successfully",
 
81
  with open(file_path, "wb") as buffer:
82
  shutil.copyfileobj(file.file, buffer)
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  except Exception as e:
86
  raise HTTPException(status_code=500, detail=f"Failed to update tables file: {str(e)}")
 
103
  )
104
  index.storage_context.persist(persist_dir=f"./lancedb/index/{table_id}")
105
 
106
+
107
+ # Store user_id and table_name in a JSON file
108
+ try:
109
+ tables_file_path = './data/tables.json'
110
+ os.makedirs(os.path.dirname(tables_file_path), exist_ok=True)
111
+ # Load existing tables or create a new file if it doesn't exist
112
+ try:
113
+ with open(tables_file_path, 'r') as f:
114
+ tables = json.load(f)
115
+ except (FileNotFoundError, json.JSONDecodeError):
116
+ tables = {}
117
+
118
+ # Update the tables dictionary
119
+ if user_id not in tables:
120
+ tables[user_id] = []
121
+ if table_id not in [table['table_id'] for table in tables[user_id]]:
122
+ tables[user_id].append({"table_id": table_id, "table_name": table_name})
123
+
124
+ # Write the updated tables back to the JSON file
125
+ with open(tables_file_path, 'w') as f:
126
+ json.dump(tables, f)
127
+
128
  return CreateTableResponse(
129
  table_id=table_id,
130
  message="Table created and documents indexed successfully",