BA-Chatbot/backend/database/es_handler.py

32 lines
966 B
Python
Raw Normal View History

2023-11-15 14:28:48 +01:00
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"))