feat(api): extract PDF hyperlinks and URLs into document metadata#512
Merged
param20h merged 1 commit intoJun 7, 2026
Merged
Conversation
param20h
approved these changes
Jun 7, 2026
|
🎉 Congratulations on getting your Pull Request merged! 🎉 Thank you for contributing to PDF-Assistant-RAG as part of GSSoC '26! 🚀 Keep up the great work! ✨ |
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.
🔗 Related Issue
Closes #441
📝 What does this PR do?
Adds automated PDF link and URL extraction during document ingestion and
exposes the results in the document metadata API.
backend/app/rag/url_extractor.py(new):extract_urls_from_pdf()— two-pass extraction per page using PyMuPDF(already in
requirements.txt): link annotations (page.get_links())first, then plain-text regex fallback for inline URLs not marked as
hyperlinks. Deduplicates while preserving first-seen order. Returns
[]safely for non-PDF files or any extraction error.
backend/migrate_add_extracted_urls.py(new):migrate_add_role.py/migrate_add_google_refresh_token.pypattern.extracted_urls TEXT DEFAULT NULLto thedocumentstable.backend/app/models.py:extracted_urls = Column(Text, nullable=True)toDocument.backend/app/schemas.py:extracted_urls: Optional[List[str]] = NonetoDocumentResponse.backend/app/services/document_ingestion.py:extract_urls_from_pdf(), JSON-serialises the result, and stores it indoc.extracted_urls. Wrapped intry/except— a failure never blocksingestion.
backend/app/routes/documents.py:_deserialize_doc()helper that parses the JSON string from the DBback into
List[str]before returningDocumentResponse. Applied toget_document,list_documents, andrename_document.🗂️ Type of Change
🧪 How was this tested?
python migrate_add_extracted_urls.py— column added successfullyuvicorn app.main:app --reload)extracted_urlsfieldin
GET /api/v1/documents/{id}response contains correct URLsextracted_urlsisnullextracted_urlsisnull✅ Self-Review Checklist
dev, notmainmainbranch or any HuggingFace deployment config