Spaces:
Sleeping
Sleeping
Update rag_routerv2.py
Browse files- rag_routerv2.py +31 -34
rag_routerv2.py
CHANGED
@@ -234,42 +234,39 @@ async def health_check():
|
|
234 |
|
235 |
@router.on_event("startup")
|
236 |
async def startup():
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
nodes = [
|
254 |
-
TextNode(text=str(row), id_=str(uuid.uuid4()))
|
255 |
-
for row in list(csv.reader(f))[1:]
|
256 |
-
]
|
257 |
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
|
|
273 |
|
274 |
@router.on_event("shutdown")
|
275 |
async def shutdown():
|
|
|
234 |
|
235 |
@router.on_event("startup")
|
236 |
async def startup():
|
237 |
+
init_db()
|
238 |
+
print("RAG Router started")
|
239 |
+
|
240 |
+
table_name = "digiyatra"
|
241 |
+
user_id = "digiyatra"
|
242 |
+
|
243 |
+
db = get_db()
|
244 |
+
# Check if table already exists
|
245 |
+
existing = db.execute('SELECT id FROM tables WHERE table_id = ?', (table_name,)).fetchone()
|
246 |
+
if not existing:
|
247 |
+
vector_store = LanceDBVectorStore(
|
248 |
+
uri="./lancedb/dev",
|
249 |
+
table_name=table_name,
|
250 |
+
mode="overwrite",
|
251 |
+
query_type="hybrid"
|
252 |
+
)
|
|
|
|
|
|
|
|
|
253 |
|
254 |
+
with open('combined_digi_yatra.csv', newline='') as f:
|
255 |
+
nodes = [TextNode(text=str(row), id_=str(uuid.uuid4()))
|
256 |
+
for row in list(csv.reader(f))[1:]]
|
257 |
|
258 |
+
index = VectorStoreIndex(nodes, vector_store=vector_store)
|
259 |
+
index.storage_context.persist(persist_dir=f"./lancedb/index/{table_name}")
|
260 |
+
|
261 |
+
db.execute(
|
262 |
+
'INSERT INTO tables (user_id, table_id, table_name) VALUES (?, ?, ?)',
|
263 |
+
(user_id, table_name, table_name)
|
264 |
+
)
|
265 |
+
db.execute(
|
266 |
+
'INSERT INTO table_files (table_id, filename, file_path) VALUES (?, ?, ?)',
|
267 |
+
(table_name, 'combined_digi_yatra.csv', 'combined_digi_yatra.csv')
|
268 |
+
)
|
269 |
+
db.commit()
|
270 |
|
271 |
@router.on_event("shutdown")
|
272 |
async def shutdown():
|