Skip to content

[Sementic search] MangoDB migration & Incremental Index Refresh#1139

Open
johngerving wants to merge 5 commits into
mainfrom
john/semantic-search-mongo
Open

[Sementic search] MangoDB migration & Incremental Index Refresh#1139
johngerving wants to merge 5 commits into
mainfrom
john/semantic-search-mongo

Conversation

@johngerving

Copy link
Copy Markdown
Contributor

Summary

Migrates the semantic search service from Redis to MongoDB Atlas Vector Search and adds incremental refresh so re-indexing only re-encodes courses whose content has actually changed.

Changes

Storage backend: Redis → MongoDB (22e65e5)

  • Replace redisvl/redis with pymongo in apps/semantic-search/requirements.txt
  • Embeddings now live in a courseEmbeddings collection alongside the rest of the app's MongoDB data, queried via $vectorSearch against an Atlas Vector Search index (course_embeddings_vector_search)
  • Add the CourseEmbeddingModel Mongoose schema in packages/common with indexes on (year, semester) and a unique (courseId, year, semester)
  • Provision the vector search index (768-dim cosine, with year/semester/subject filter fields) in docker/mongodb/init/01-create-search-indexes.js
  • Update docker-compose.yml to depend on mongodb (healthy) and swap REDIS_URIMONGODB_URI

Drop embedding-result caching (205cac3)

  • Embeddings are now persisted directly per-course in MongoDB, so the previous in-process / Redis cache layer is gone

Incremental refresh (605cb79)

  • refresh() now hashes each course's text (SHA-256), compares against contentHash stored in MongoDB, and only re-encodes courses that are new or changed
  • Courses removed from the catalog are deleted via a bulk DeleteOne pass
  • Old terms beyond the most recent max_terms are evicted from MongoDB on each refresh

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 605cb79b04

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +18 to +19
{ courseId: 1, year: 1, semester: 1 },
{ unique: true }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Include subject in unique embedding index key

The unique index on (courseId, year, semester) conflicts with how embeddings are currently written in apps/semantic-search/app/engine.py (it populates courseId from courseNumber, not the globally unique Class.courseId). Because courseNumber values repeat across departments (for example many subjects have the same catalog number in a term), refresh can hit duplicate-key BulkWriteError during upserts and leave the semantic index build failed or partial. Including subject in this unique key (or storing the true courseId) is needed to avoid cross-department collisions.

Useful? React with 👍 / 👎.

@vaclisinc vaclisinc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So far great work! I will first deploy on dev and also test on local dev now, and do code review asap.

BTW, just a reminder, after you create the PR, remember also deploy to dev in the future!

@vaclisinc vaclisinc changed the title Incremental Semantic Search Index Refresh [Sementic search] MangoDB migration & Incremental Index Refresh Apr 30, 2026
@vaclisinc vaclisinc self-requested a review May 6, 2026 05:09
Comment on lines +325 to +338

try:
raw_results = list(self._embeddings_col.aggregate(pipeline))
except Exception as exc:
raise RuntimeError(
f"Vector search failed for {semester} {year}. "
"The search index may still be building. Please try again shortly."
) from exc

scored = [
(r["score"], r.get("subject"), r.get("courseId"))
for r in raw_results
if r.get("score", 0.0) >= threshold
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if the index is not ready, it shouldn't provide the option for ppl to use semantic search - need to deep into

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.

2 participants