Skip to content

Commit

Permalink
Feature/basic retrieval (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinsws authored Jun 21, 2024
1 parent 83cd32a commit e02165f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/pipeline/chat/tutor_chat_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ def _run_tutor_chat_pipeline(
)
self._add_relevant_chunks_to_prompt(retrieved_lecture_chunks)

retrieved_lecture_chunks = self.retriever(
chat_history=history,
student_query=query.contents[0].text_content,
result_limit=10,
course_name=dto.course.name,
course_id=dto.course.id,
problem_statement=problem_statement,
exercise_title=exercise_title,
)
self._add_relevant_chunks_to_prompt(retrieved_lecture_chunks)

self.callback.in_progress("Generating response...")

# Add the final message to the prompt and run the pipeline
Expand Down
29 changes: 29 additions & 0 deletions app/retrieval/lecture_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,35 @@ def __call__(
return [merged_chunks[int(i)] for i in selected_chunks_index]
return []

def basic_lecture_retrieval(
self,
chat_history: list[PyrisMessage],
student_query: str,
result_limit: int,
course_name: str = None,
course_id: int = None,
base_url: str = None,
) -> list[dict[str, dict]]:
"""
Basic retrieval for pipelines thaat need performance and fast answers.
"""
rewritten_query = self.rewrite_student_query(
chat_history, student_query, "course_language", course_name
)
response = self.search_in_db(
query=rewritten_query,
hybrid_factor=0.9,
result_limit=result_limit,
course_id=course_id,
base_url=base_url,
)

basic_retrieved_lecture_chunks: list[dict[str, dict]] = [
{"id": obj.uuid.int, "properties": obj.properties}
for obj in response.objects
]
return basic_retrieved_lecture_chunks

def rewrite_student_query(
self,
chat_history: list[PyrisMessage],
Expand Down

0 comments on commit e02165f

Please sign in to comment.