2023-09-15 16:52:06 +03:00
|
|
|
from celery import shared_task
|
|
|
|
from models.brains import Brain
|
2023-09-16 00:39:29 +03:00
|
|
|
from models.settings import get_supabase_db
|
2023-11-14 16:31:02 +03:00
|
|
|
from packages.embeddings.vectors import Neurons
|
2023-09-15 16:52:06 +03:00
|
|
|
from repository.files.upload_file import DocumentSerializable
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
2023-11-19 20:46:12 +03:00
|
|
|
def create_embedding_for_document(brain_id, doc_with_metadata, file_sha1):
|
2023-09-15 16:52:06 +03:00
|
|
|
neurons = Neurons()
|
|
|
|
doc = DocumentSerializable.from_json(doc_with_metadata)
|
2023-11-19 20:46:12 +03:00
|
|
|
created_vector = neurons.create_vector(doc)
|
2023-09-16 00:39:29 +03:00
|
|
|
database = get_supabase_db()
|
|
|
|
database.set_file_sha_from_metadata(file_sha1)
|
|
|
|
|
2023-09-15 16:52:06 +03:00
|
|
|
created_vector_id = created_vector[0] # pyright: ignore reportPrivateUsage=none
|
|
|
|
|
2023-09-16 17:49:31 +03:00
|
|
|
brain = Brain(id=brain_id) # pyright: ignore
|
2023-09-15 16:52:06 +03:00
|
|
|
brain.create_brain_vector(created_vector_id, file_sha1)
|