feat: index webpages - #3596
Open
akiva10b wants to merge 1 commit into
Open
Conversation
📊 Code Quality Score: 50/100
Was this score accurate? 👍 Yes · 👎 No Scored by GitVelocity · How are scores calculated? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
flowchart LR A["Sefaria Linker"] --> B["MongoDB"] B --> C["Celery indexing task"] C --> D["Clean and chunk content"] D --> E["Generate embeddings"] E --> F["Elasticsearch webpage index"] G["AI agent search tool"] --> H["Search API"] H --> FThis PR adds an agent-facing search service for webpage content collected by the Sefaria Linker. It supports:
Architecture
MongoDB remains the source of truth:
webpagesstores page metadata and detected refs.webpages_textstores the extracted title and full page content.When
WebPageTextchanges, a Celery task cleans and chunks the page content, generates embeddings, and indexes each passage in a dedicated Elasticsearch index. Existing chunks for the URL are replaced when its content changes.Each indexed passage includes:
Website IDs, domains, refs, expanded refs, and languages are indexed as exact-match fields. Titles and content are indexed for full-text retrieval.
Search behavior
The search service supports:
Ref filters are normalized through
Ref. Sections and ranges are expanded to segment refs and matched againstexpanded_refs.Page-level refs are initially copied to every passage from that page. A future improvement could associate refs only with the passages where they occur.
Agent API
The bounded search interface accepts:
Results include the page title, URL, matching passage, relevance score, website metadata, and associated refs. Domain and ref normalization are handled by the API rather than the calling agent.
Operations
The implementation uses Sefaria’s existing Elasticsearch, MongoDB, Celery, and embedding infrastructure. It includes:
Hybrid retrieval is the default,
website_idis the canonical website filter,domainprovides hostname-level filtering, andexpanded_refssupports segment-level ref filtering.