Skip to content

ДЗ2: MVP проекта CineMatch - #4

Open
tsisarukm wants to merge 1 commit into
hw-basefrom
hw2/mvp
Open

ДЗ2: MVP проекта CineMatch#4
tsisarukm wants to merge 1 commit into
hw-basefrom
hw2/mvp

Conversation

@tsisarukm

Copy link
Copy Markdown
Collaborator

ДЗ2: MVP проекта CineMatch

Артефакты

  • src/ — исходный код RAG-пайплайна (query_analyzer, retrieval, rag, hallucination, llm_utils, app)
  • scripts/ — скрипты подготовки данных и оценки (ingest, build_index, evaluate)
  • config.yaml, prompts.yaml — конфигурация системы и промпты
  • requirements.txt — зависимости
  • reports/hw2_report.md — отчёт по этапу

Что реализовано

5-этапный RAG-пайплайн:

  1. Query Analyzer — парсит свободный текст в структурированные параметры (жанр, настроение, ограничения)
  2. Hybrid Retrieval — векторный поиск ChromaDB + фильтры по метаданным → 20 кандидатов
  3. Cross-Encoder Reranking — переранжирование → top-5
  4. Hallucination Guard — проверка порога сходства (≥ 0.4)
  5. LLM Generation — объяснения на языке пользователя

Запуск

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python scripts/ingest.py
python scripts/build_index.py
streamlit run src/app.py

Comment thread config.yaml

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше сделать pydantic модель для валидации модели

Comment thread src/query_analyzer.py

PROJECT_ROOT = Path(__file__).resolve().parent.parent

with open(PROJECT_ROOT / "config.yaml") as f:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем в каждом файле парсить конфиг заново?

Comment thread src/llm_utils.py
print(f"LLM error ({current_model}, attempt {attempt + 1}/{max_retries + 1}): {e}")
if attempt < max_retries:
sleep_time = backoff_base ** (attempt + 1)
print(f" Retrying in {sleep_time:.0f}s...")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше все print на logging заменить

Comment thread src/query_analyzer.py
Comment on lines +69 to +74
raw = llm_call_with_retry(
self.client, self.model, messages,
fallback_models=self.fallback_models,
max_retries=self.max_retries,
backoff_base=self.backoff_base,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше использовать response_format, чтобы модель генерировала в нужном формате

Comment thread src/query_analyzer.py
Comment on lines +89 to +96
return {
"genre": parsed.get("genre"),
"mood": parsed.get("mood"),
"max_duration": parsed.get("max_duration"),
"min_year": parsed.get("min_year"),
"min_rating": parsed.get("min_rating"),
"semantic_query": parsed["semantic_query"],
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше использовать dataclass/typeddict

Comment thread src/rag.py
Comment on lines +53 to +64
conn.execute("""
CREATE TABLE IF NOT EXISTS logs (
request_id TEXT PRIMARY KEY,
timestamp REAL,
user_query TEXT,
parsed_query TEXT,
retrieved_movie_ids TEXT,
llm_response TEXT,
latency_ms REAL,
feedback TEXT
)
""")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не использовали sqlalchemy для таблиц и запросов?

Comment thread src/rag.py
movie_ids: list[str], response: str, latency_ms: float):
"""Log request to SQLite."""
try:
conn = sqlite3.connect(str(self.db_path))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не использовать общий connection?

Comment thread src/rag.py
except Exception as e:
print(f"Feedback save error: {e}")

def _clean_json_response(self, text: str) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В другом классе уже есть эта функция

Comment thread requirements.txt

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше использовать pyproject и туда добавить линтеры и форматтеры

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants