From 2f8d5cae259ecbcd3e1aecadbe35060a864223d1 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Wed, 25 Sep 2024 03:57:02 +0800 Subject: [PATCH 1/2] fix: add unique id for vector embedding for consistent upserts with no duplicated events --- backend/src/embeddings/vector_store.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/src/embeddings/vector_store.py b/backend/src/embeddings/vector_store.py index 461f0259..29a2776c 100644 --- a/backend/src/embeddings/vector_store.py +++ b/backend/src/embeddings/vector_store.py @@ -68,8 +68,15 @@ def store_documents(): ) documents.append(document) - uuids = [str(uuid4()) for _ in range(len(documents))] - vector_store.add_documents(documents=documents, ids=uuids) + ids = [ + str(document.metadata["id"]) + + "-" + + str(document.metadata["event_id"]) + + "-" + + str(document.metadata["category_id"]) + for document in documents + ] + vector_store.add_documents(documents=documents, ids=ids) print(f"Stored {len(documents)} documents") From 7e048e49f6bc6de4da05f3f274f504789d91ff96 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Wed, 25 Sep 2024 04:11:37 +0800 Subject: [PATCH 2/2] feat: add endpoint for gp question point gen --- backend/src/user_questions/router.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/user_questions/router.py b/backend/src/user_questions/router.py index 097e1fc5..5ea9e994 100644 --- a/backend/src/user_questions/router.py +++ b/backend/src/user_questions/router.py @@ -10,6 +10,7 @@ from src.notes.models import Note from src.user_questions.models import Answer, Point, UserQuestion from src.user_questions.schemas import CreateUserQuestion, UserQuestionMiniDTO +from src.lm.generate_points import get_relevant_analyses router = APIRouter(prefix="/user-questions", tags=["user-questions"]) @@ -91,3 +92,8 @@ def create_user_question( session.commit() session.refresh(user_question) return user_question + + +@router.get("/ask-gp-question") +def ask_gp_question(question: str): + return get_relevant_analyses(question)