|
|
|
@@ -9,7 +9,7 @@ import lib
|
|
|
|
|
import json
|
|
|
|
|
import psycopg2
|
|
|
|
|
import pymongo
|
|
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
import mongo_conn
|
|
|
|
|
import pgvec_conn
|
|
|
|
|
import redis_conn
|
|
|
|
@@ -40,16 +40,24 @@ def retrieve_file_contents(path, pPullFromS3):
|
|
|
|
|
lib.read_files(path, files := [])
|
|
|
|
|
|
|
|
|
|
contents = []
|
|
|
|
|
ctime = ""
|
|
|
|
|
mtime = ""
|
|
|
|
|
|
|
|
|
|
print("parsing files...")
|
|
|
|
|
for file in tqdm(files):
|
|
|
|
|
if not pPullFromS3:
|
|
|
|
|
ctime = datetime.fromtimestamp(os.path.getctime(file[1])).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
mtime = datetime.fromtimestamp(os.path.getmtime(file[1])).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
print(ctime, mtime)
|
|
|
|
|
content = file_extraction_functions[file[0]](file[1])
|
|
|
|
|
if not pPullFromS3:
|
|
|
|
|
push_files_into_s3(file, content, minioClient)
|
|
|
|
|
|
|
|
|
|
contents.append({
|
|
|
|
|
"type": file[0],
|
|
|
|
|
"path": file[1] if not pPullFromS3 else "Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ",
|
|
|
|
|
"ctime": ctime if not pPullFromS3 else 'Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ',
|
|
|
|
|
"mtime": mtime if not pPullFromS3 else 'Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ',
|
|
|
|
|
"path": file[1] if not pPullFromS3 else 'Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ',
|
|
|
|
|
"filename": file[2],
|
|
|
|
|
"content": content
|
|
|
|
|
})
|
|
|
|
@@ -96,16 +104,18 @@ def create_embeddings(pContent):
|
|
|
|
|
insert_data = f"insert into dbtable (filepath, embedding) Values ('{content['path']}', %s) Returning id;"
|
|
|
|
|
cur.execute(insert_data, (response["embedding"],))
|
|
|
|
|
doc_id = cur.fetchone()[0]
|
|
|
|
|
insert_data_mongo(doc_id, content['path'], chunk)
|
|
|
|
|
insert_data_mongo(doc_id, content['path'], chunk, content['ctime'], content["mtime"])
|
|
|
|
|
conn.commit()
|
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
|
|
def insert_data_mongo(id, filepath,pChunk):
|
|
|
|
|
def insert_data_mongo(id, filepath,pChunk, pCtime, pMtime):
|
|
|
|
|
client = pymongo.MongoClient('mongodb://python:PasswordPassword123@localhost:27017/')
|
|
|
|
|
mongodb = client['document_table']
|
|
|
|
|
collection = mongodb['documents']
|
|
|
|
|
dokument = {
|
|
|
|
|
'doc_id': id,
|
|
|
|
|
'ctime' : pCtime,
|
|
|
|
|
'mtime' : pMtime,
|
|
|
|
|
'filepath': filepath,
|
|
|
|
|
'chunk_content': pChunk,
|
|
|
|
|
}
|
|
|
|
|