puuuush
This commit is contained in:
@@ -55,7 +55,7 @@ def prompt_embedding(prompt):
|
|||||||
)
|
)
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
|
||||||
cur.execute(f"select id, filepath, embedding <-> %s::vector as distance from dbtable order by distance limit 10;", (embedding["embedding"],))
|
cur.execute(f"select id, doc_id, filepath, embedding <-> %s::vector as distance from dbtable order by distance limit 3;", (embedding["embedding"],))
|
||||||
|
|
||||||
result = cur.fetchall()
|
result = cur.fetchall()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import ollama
|
import ollama
|
||||||
import pymupdf
|
import pymupdf
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import chunker
|
||||||
import lib
|
import lib
|
||||||
import json
|
import json
|
||||||
import psycopg2
|
import psycopg2
|
||||||
@@ -60,20 +62,20 @@ def create_embeddings(pContent):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
for content in pContent:
|
for content in pContent:
|
||||||
merged_info = "Dateiname: " + content["filename"] + " Dateiinhalt: " + content[
|
for chunk in chunker.generate_chunks(content["content"]):
|
||||||
"content"] # Bessere Embeddings mit Dateiname // Information vorne dran?
|
merged_info = "Dateiname: " + content["filename"] + " Dateiinhalt: " + chunk
|
||||||
# print(merged_info)
|
# print(merged_info)
|
||||||
response = ollama.embeddings(model="mxbai-embed-large", prompt=merged_info)
|
response = ollama.embeddings(model="mxbai-embed-large", prompt=merged_info)
|
||||||
#embedding_list.append(response["embedding"])
|
#embedding_list.append(response["embedding"])
|
||||||
insert_data = f"insert into dbtable (filepath, embedding) Values ('{content['path']}', %s) Returning doc_id;"
|
insert_data = f"insert into dbtable (filepath, embedding) Values ('{content['path']}', %s) Returning doc_id;"
|
||||||
cur.execute(insert_data, (response["embedding"],))
|
cur.execute(insert_data, (response["embedding"],))
|
||||||
doc_id = cur.fetchone()[0]
|
doc_id = cur.fetchone()[0]
|
||||||
insert_data_mongo(doc_id, "Hello World")
|
insert_data_mongo(doc_id, chunk)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
def insert_data_mongo(id, pChunk):
|
def insert_data_mongo(id, pChunk):
|
||||||
client = pymongo.MongoClient('mongodb://localhost:27017/')
|
client = pymongo.MongoClient('mongodb://python:PasswordPassword123@localhost:27017/')
|
||||||
mongodb = client['document_table']
|
mongodb = client['document_table']
|
||||||
collection = mongodb['documents']
|
collection = mongodb['documents']
|
||||||
dokument = {
|
dokument = {
|
||||||
@@ -84,7 +86,7 @@ def insert_data_mongo(id, pChunk):
|
|||||||
|
|
||||||
def reload_files():
|
def reload_files():
|
||||||
# path = input("Please provider path to folder: ")
|
# path = input("Please provider path to folder: ")
|
||||||
contents = retrieve_file_contents("C:\\Users\\afist\\Downloads\\SoftwareEng")
|
contents = retrieve_file_contents("C:\\SoftwareEng")
|
||||||
create_embeddings(contents)
|
create_embeddings(contents)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user