1
0
Fork 0
BA-Chatbot_Ali_Thesis/backend/database/es_handler.py

32 lines
966 B
Python
Executable File

from haystack.document_stores.elasticsearch import ElasticsearchDocumentStore
import os
import sys
sys.path.append('/root/home/BA_QA_HSMA/backendd')
class ElasticSearchData:
def __init__(self) -> None:
self.doc_store = ElasticsearchDocumentStore(port=9210)
pass
def write_data(self, data, index):
return self.doc_store.write_documents(documents=data, index=index)
def get_data(self, index):
return self.doc_store.get_all_documents(index=index)
def get_all_doc_count(self,index):
return self.doc_store.get_document_count(index=index)
def delete_all_docs(self, index):
return self.doc_store.delete_all_documents(index=index)
def remove_docs(self):
pass
def update_embeddings(self, retriever):
return self.doc_store.update_embeddings(retriever=retriever, index="ib")
if __name__ == "__main__":
es = ElasticSearchData()
print(es.delete_all_docs(index="ib"))