Spaces:
Sleeping
Sleeping
DEBUG: Hybrid Search
Browse files- functions.py +42 -52
functions.py
CHANGED
@@ -100,60 +100,50 @@ def matchPassword(username: str, password: str) -> str:
|
|
100 |
|
101 |
|
102 |
def createTable(tablename: str):
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
}
|
116 |
-
except Exception as e:
|
117 |
-
return {
|
118 |
-
"error": e
|
119 |
-
}
|
120 |
|
121 |
def addDocuments(text: str, vectorstore: str):
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
}
|
153 |
-
except Exception as e:
|
154 |
-
return {
|
155 |
-
"error": e
|
156 |
-
}
|
157 |
|
158 |
|
159 |
def format_docs(docs: str):
|
|
|
100 |
|
101 |
|
102 |
def createTable(tablename: str):
|
103 |
+
qdrant = QdrantVectorStore.from_documents(
|
104 |
+
documents = [],
|
105 |
+
embedding = vectorEmbeddings,
|
106 |
+
sparse_embedding=sparseEmbeddings,
|
107 |
+
url=os.environ["QDRANT_URL"],
|
108 |
+
prefer_grpc=True,
|
109 |
+
api_key=os.environ["QDRANT_API_KEY"],
|
110 |
+
collection_name=tablename
|
111 |
+
)
|
112 |
+
return {
|
113 |
+
"output": "SUCCESS"
|
114 |
+
}
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
def addDocuments(text: str, vectorstore: str):
|
117 |
+
global vectorEmbeddings
|
118 |
+
global sparseEmbeddings
|
119 |
+
global store
|
120 |
+
parentSplitter = RecursiveCharacterTextSplitter(
|
121 |
+
chunk_size = 2100,
|
122 |
+
add_start_index = True
|
123 |
+
)
|
124 |
+
childSplitter = RecursiveCharacterTextSplitter(
|
125 |
+
chunk_size = 300,
|
126 |
+
add_start_index = True
|
127 |
+
)
|
128 |
+
texts = [Document(page_content = text)]
|
129 |
+
vectorstore = QdrantVectorStore.from_existing_collection(
|
130 |
+
embedding = vectorEmbeddings,
|
131 |
+
sparse_embedding=sparseEmbeddings,
|
132 |
+
collection_name=vectorstore,
|
133 |
+
url=os.environ["QDRANT_URL"],
|
134 |
+
api_key=os.environ["QDRANT_API_KEY"],
|
135 |
+
retrieval_mode=RetrievalMode.HYBRID
|
136 |
+
)
|
137 |
+
retriever = ParentDocumentRetriever(
|
138 |
+
vectorstore=vectorstore,
|
139 |
+
docstore=store,
|
140 |
+
child_splitter=childSplitter,
|
141 |
+
parent_splitter=parentSplitter
|
142 |
+
)
|
143 |
+
retriever.add_documents(documents = texts)
|
144 |
+
return {
|
145 |
+
"output": "SUCCESS"
|
146 |
+
}
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
|
149 |
def format_docs(docs: str):
|