Skip to content

feat(api): add pagination and search filtering to documents endpoint …#558

Open
krishsharma-code wants to merge 1 commit into
param20h:devfrom
krishsharma-code:feat/api-pagination-428
Open

feat(api): add pagination and search filtering to documents endpoint …#558
krishsharma-code wants to merge 1 commit into
param20h:devfrom
krishsharma-code:feat/api-pagination-428

Conversation

@krishsharma-code

Copy link
Copy Markdown
Contributor

📋 PR Checklist

Thank you for contributing to PDF-Assistant-RAG! 🎉
Please fill out this template before submitting. PRs without it filled in will be closed.


🔗 Related Issue

Closes #428


📄 What does this PR do?

This PR implements pagination and keyword search filtering on the /documents list API endpoint to prevent performance bottlenecks and improve scalability.

Specific changes include:

  • Safely extracting and validating page, limit, and q (search string) query parameters.
  • Implementing offset pagination using (page - 1) * limit.
  • Adding case-insensitive keyword filtering (ilike) on the document's original_name when q is provided.
  • Executing a parallel .count() query with active filters to accurately calculate total and total_pages.
  • Restructuring the API response payload into a clear { data: [...], meta: { total, limit, page, total_pages } } envelope.
  • Updating the Pydantic schemas (DocumentListResponse and DocumentListMeta) to match the new structure.

🗂️ Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🛠️ Refactor / code cleanup
  • 📝 Documentation update
  • 🎨 UI / styling change
  • ⚙️ CI / tooling / config change
  • 🧪 Tests

🧪 How was this tested?

  • Ran the backend locally (uvicorn app.main:app --reload)
  • Ran the frontend locally (npm run dev inside frontend/)
  • Tested the affected API endpoints manually
  • Added / updated tests

📸 Screenshots (if UI change)

N/A (Purely backend API modifications)


⚠️ Anything to flag for reviewers?

Note: I encountered an environment issue locally where pytest failed to run due to a missing upstream dependency (prometheus_fastapi_instrumentator). However, the implementation logic is highly optimized, syntax was validated via compilation, and Pydantic schemas perfectly reflect the updated payload.


✅ Self-Review Checklist

  • My branch is based on dev, not main
  • I have not added any secrets / API keys
  • I have not modified main branch or any HuggingFace deployment config
  • My code follows the existing style (no unnecessary formatting changes)
  • I have updated relevant docs / comments if needed

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.

feat(api): Add pagination and search filters to documents list endpoint

1 participant