From 68e699f38f67d2c4cb8fa433cd95e3bc1670fba7 Mon Sep 17 00:00:00 2001 From: Ali Date: Tue, 10 Dec 2024 23:17:02 +0100 Subject: [PATCH] puuuuush Puuuuush it babyyyyy DEEEEEEPER --- main.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 0951d05..aa50c6d 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,11 @@ +import ollama import pymupdf import os import lib import json +import psycopg2 + + def retrieve_file_contents(path): file_extraction_functions = { @@ -30,5 +34,50 @@ def retrieve_file_contents(path): contents = retrieve_file_contents("C:\\Users\\afist\\Downloads\\SoftwareEng") +embedding_list = [] -print(json.dumps(contents, indent="\t")) \ No newline at end of file +def create_embeddings(pContent): + conn = psycopg2.connect( + dbname="embeddings", + user="python", + password="PasswordPassword123", + host="localhost", + port="5555" + ) + cur = conn.cursor() + + create_table_query = ''' + create table if not exists dbtable ( + id SERIAL PRIMARY KEY, + filename TEXT NOT NULL, + embedding VECTOR NOT NULL + ) + ''' + + + cur.execute(create_table_query) + + cur.execute('CREATE EXTENSION IF NOT EXISTS vector;') + for content in pContent: + merged_info = "Dateiname: " + content["filename"] + " Dateiinhalt: " + content[ + "content"] # Bessere Embeddings mit Dateiname // Information vorne dran? + # print(merged_info) + response = ollama.embeddings(model="mxbai-embed-large", prompt=merged_info) + #embedding_list.append(response["embedding"]) + insert_data = f'insert into dbtable (filepath, embedding) Values ({content["filepath"]}, {response["embedding"]});' + cur.execute(insert_data) + + conn.commit() + conn.close() + + + + + + + + +create_embeddings(contents) + + +#print(json.dumps(contents, indent="\t")) \ No newline at end of file