Building Sherlock PDF: How LangChain Enables Semantic Literature Search
A LangChain tutorial demonstrates Sherlock PDF, an open-source tool that pairs vector embeddings with exact page numbers to streamline academic literature search.

Researchers frequently struggle to pinpoint specific findings buried across scores of scientific preprints and journal articles. While traditional keyword queries often miss passages that use alternative phrasing, relying on ungrounded language models introduces risks of factual hallucination. To address this literature retrieval challenge, developer Suvra Nath introduced "Sherlock PDF," an open-source tutorial demonstrating how to assemble a semantic search pipeline for scientific literature using LangChain and OpenAI embeddings. The tool allows researchers to ask natural-language questions and receive matching excerpts accompanied by exact source filenames and page numbers.
Architecture and semantic retrieval pipeline
Sherlock PDF is built for Python 3.10+ environments and relies on modular components from the LangChain ecosystem. The workflow begins by loading local documents from a designated folder using DirectoryLoader paired with PyMuPDFLoader. The extracted text is then segmented via RecursiveCharacterTextSplitter with a chunk size of 220 characters and an overlap of 40 characters, splitting content across paragraphs and spaces while preserving original document metadata.
Once split, the text chunks are converted into numerical representations using OpenAI's text-embedding-3-small model. These vectors are indexed locally using LangChain's InMemoryVectorStore. When a user submits a query, the application embeds the question and calculates cosine similarity against the stored chunks. Cosine similarity evaluates the angle between vectors rather than their length, generating a score near 1 for semantically aligned text and near 0 for unrelated content.
This semantic approach allows the tool to connect conceptual equivalents without requiring identical keywords. For instance, a query asking whether sleep makes hippocampal connections weaker can successfully surface excerpts discussing synaptic downscaling during slow-wave sleep in CA3. To ensure reproducibility, Sherlock PDF extracts the zero-indexed page number provided by PyMuPDF, increments it by one, and reports the exact printed page alongside the document name and similarity score.
Architectural constraints and deployment scope
The current implementation is designed as a lightweight prototype rather than a permanent knowledge base. Because it relies on an in-memory vector store, the entire document set is re-embedded on every execution. Nath notes that scaling the system to manage thousands of papers requires swapping the memory store for persistent solutions such as Chroma, FAISS, Pinecone, or PostgreSQL with pgvector.
The pipeline also has practical boundaries regarding document formats and data privacy. Because PyMuPDF extracts existing text, scanned image PDFs require an optical character recognition (OCR) step before ingestion. Additionally, because document chunks are transmitted externally to OpenAI to produce embeddings, developers and researchers must ensure that unpublished manuscripts or proprietary research comply with their organization's data privacy policies. Nath also emphasizes that semantic retrieval is not a substitute for traditional reference managers like EndNote or Mendeley, which focus on citation management and collaboration rather than conceptual search.
What it means for developers
For developers building retrieval-augmented generation (RAG) and search applications, Sherlock PDF illustrates the importance of evidence attribution over ungrounded generative summaries. Rather than asking a large language model to synthesize an unverified answer, the pipeline functions as a targeted retrieval assistant, pointing users directly to source coordinates where findings can be checked in context.
Developers building similar document search tools must pay close attention to metadata propagation. When splitting documents, preserving file paths and adjusting zero-based page offsets ensures that end users receive verifiable citations. In addition, using compact embedding models keeps operational costs low—amounting to only cents for multiple research papers. Developers looking to implement or test embedding and retrieval pipelines can try top AI models cheaply through one API at https://apixoai.online.
Ultimately, the implementation demonstrates that practical search tools do not always require complex infrastructure. By combining basic chunking strategies, cosine similarity, and structured metadata tracking, developers can deploy targeted document retrieval workflows that prioritize factual verification.
Source: A Hands-On LangChain Tutorial: Building “Sherlock PDF” for Smarter Scientific Literature Search — Towards AI. Written by the Apixo team from that report.
One key for Claude, GPT, GLM, DeepSeek and more. Pay per token with crypto.
Get your API key

