Skip to content

scientific rag pipeline with hybrid retrieval, multi-style citations, and semantic scholar integration#2

Open
ykd007 wants to merge 1 commit into
ISAAC-chatbot:ver5from
ykd007:feat/scientific-rag-pipeline
Open

scientific rag pipeline with hybrid retrieval, multi-style citations, and semantic scholar integration#2
ykd007 wants to merge 1 commit into
ISAAC-chatbot:ver5from
ykd007:feat/scientific-rag-pipeline

Conversation

@ykd007

@ykd007 ykd007 commented May 14, 2026

Copy link
Copy Markdown

This adds a full scientific RAG pipeline under a rag/ module. Here's what's in it:

rag/pipeline.py — ScientificRAGPipeline
The main class that ties everything together. Accepts uploaded files or Semantic Scholar paper IDs, retrieves the most relevant chunks for a query using hybrid search, then generates a grounded answer via OpenAI. Supports both blocking and streaming (SSE) modes.

rag/hybrid_retriever.py — HybridRetriever
Combines BM25 keyword search (pure Python, no deps) with dense cosine similarity via any embedding function. The alpha parameter lets you tune how much weight to give each signal. Falls back to BM25 only if embeddings aren't available. Per-user isolation is built in so one user can't see another's private documents.

rag/document_manager.py — DocumentManager
Handles PDF (pdfminer or PyPDF2), DOCX (python-docx), TXT, MD, and HTML. Chunks with configurable size and overlap. Deduplicates by content hash so uploading the same file twice is a no-op.

rag/semantic_scholar.py — SemanticScholarClient
Thin wrapper around the Semantic Scholar Graph API. Supports search, single-paper fetch, references, and citations. Handles 429 rate limiting with automatic backoff. Works without an API key (1 req/s) or faster with one.

rag/citation_manager.py — CitationManager
Formats paper dicts into APA, MLA, Chicago, IEEE, Harvard, Vancouver, or BibTeX strings.

rag/api_routes.py — FastAPI router
Mounts under /rag — endpoints for document upload, document list/delete, paper search, paper ingest, blocking query, and SSE streaming query. Just app.include_router(rag_router) to wire it in.

tests/test_rag.py
16 unit tests, all passing. Cover BM25 retrieval, user isolation, vector blending, all 7 citation styles, document deduplication, unsupported file rejection, and mocked S2 API calls.

Closes #45

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.

1 participant