andreasmartin commited on
Commit
96db48f
·
1 Parent(s): 5005601

deepnote update

Browse files
Files changed (1) hide show
  1. faq.py +10 -13
faq.py CHANGED
@@ -21,11 +21,7 @@ def faq_id(sheet_url: str) -> str:
21
  return sheet_url[x + len(sheet_url_x) : y] + "-" + sheet_url[y + len(sheet_url_y) :]
22
 
23
 
24
- def xlsx_url(sheet_url: str) -> str:
25
- return sheet_url.replace(sheet_url_y, sheet_url_y_exp)
26
-
27
-
28
- def xlsx_url_faq_id(faq_id: str) -> str:
29
  y = faq_id.rfind("-")
30
  return sheet_url_x + faq_id[0:y] + sheet_url_y_exp + faq_id[y + 1 :]
31
 
@@ -49,24 +45,25 @@ def embedding_function(model_name: str) -> HuggingFaceEmbeddings:
49
 
50
  def vectordb(
51
  faq_id: str,
52
- documents: List[Document],
53
  embedding_function: Embeddings,
54
- init: bool = False,
55
  ) -> VectorStore:
56
  vectordb = None
57
- if init:
58
- vectordb = AwaDB.from_documents(
59
- documents=documents,
60
  embedding=embedding_function,
61
- table_name=faq_id,
62
  log_and_data_dir=dir_vectordb
63
  )
 
 
 
64
  else:
65
- vectordb = AwaDB(
 
66
  embedding=embedding_function,
 
67
  log_and_data_dir=dir_vectordb
68
  )
69
- vectordb.load_local(table_name=faq_id)
70
  return vectordb
71
 
72
 
 
21
  return sheet_url[x + len(sheet_url_x) : y] + "-" + sheet_url[y + len(sheet_url_y) :]
22
 
23
 
24
+ def xlsx_url(faq_id: str) -> str:
 
 
 
 
25
  y = faq_id.rfind("-")
26
  return sheet_url_x + faq_id[0:y] + sheet_url_y_exp + faq_id[y + 1 :]
27
 
 
45
 
46
  def vectordb(
47
  faq_id: str,
 
48
  embedding_function: Embeddings,
49
+ documents: List[Document] = None
50
  ) -> VectorStore:
51
  vectordb = None
52
+ if documents is None:
53
+ vectordb = AwaDB(
 
54
  embedding=embedding_function,
 
55
  log_and_data_dir=dir_vectordb
56
  )
57
+ success = vectordb.load_local(table_name=faq_id)
58
+ if not success:
59
+ raise Exception("faq_id may not exists")
60
  else:
61
+ vectordb = AwaDB.from_documents(
62
+ documents=documents,
63
  embedding=embedding_function,
64
+ table_name=faq_id,
65
  log_and_data_dir=dir_vectordb
66
  )
 
67
  return vectordb
68
 
69