quivr/backend/repository/brain/get_question_context_from_brain.py
Mamadou DICKO ba123fe716
feat(shareBrain): prevent re inviting users with access (#1063)
* fix(shareBrain): prevent access duplication in db

* feat: remove unused function

* fix(linter): update types
2023-08-30 15:55:06 +02:00

21 lines
631 B
Python

from uuid import UUID
from models.settings import get_embeddings, get_supabase_client
from vectorstore.supabase import CustomSupabaseVectorStore
def get_question_context_from_brain(brain_id: UUID, question: str) -> str:
supabase_client = get_supabase_client()
embeddings = get_embeddings()
vector_store = CustomSupabaseVectorStore(
supabase_client,
embeddings,
table_name="vectors",
brain_id=str(brain_id),
)
documents = vector_store.similarity_search(question)
# aggregate all the documents into one string
return "\n".join([doc.page_content for doc in documents])