Semantic Search Engine Using Langchain
Author(s): Lo Zarantonello
Originally published on Towards AI.
Load and query a PDF locally using Langchain
This member-only story is on us. Upgrade to access all of Medium.
In this post, I am loosely following Build a semantic search engine on Lnagchain, adding some explanation about Embeddings and Vector Store.
We start by installing @langchain/community and pdf-parse in a new directory.
npm i @langchain/community pdf-parseThe @langchain/community package contains a range of third-party integrationsThe pdf-parse package is a “pure javascript cross-platform module to extract texts from PDFs.”
Below, you can see how @langchain/community fits into the Langchain ecosystem.
In the same directory, we can create a new index.js file and add the following code.
import { PDFLoader } from "@langchain/community/document_loaders/fs/pdf";const loader = new PDFLoader("./pdfs/letter-to-shareholders-amazon.pdf");// loads one Document object per PDF pageconst docs = await loader.load();console.log(docs.length);
PDFLoader loads one Document object per PDF page. So, in my case, docs is an array of 8 Document objects because the PDF is 8 pages long.
// Document object{ pageContent: String, metadata: { source: './pdfs/letter-to-shareholders-amazon.pdf', pdf: { version: '1.10.100', info: [Object], metadata: null, totalPages: 8 }, loc: { pageNumber: 1 } }, id: undefined}
To run the loader in a node environment, we can simply run
node index.js
Node doesn’t recognize ES modules by default so we need to add the following type field in package.json.
{ "dependencies": { "@langchain/community": "^0.3.28",… Read the full blog for free on Medium.
Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.
Published via Towards AI
Towards AI Academy
We Build Enterprise-Grade AI. We'll Teach You to Master It Too.
15 engineers. 100,000+ students. Towards AI Academy teaches what actually survives production.
Start free — no commitment:
→ 6-Day Agentic AI Engineering Email Guide — one practical lesson per day
→ Agents Architecture Cheatsheet — 3 years of architecture decisions in 6 pages
Our courses:
→ AI Engineering Certification — 90+ lessons from project selection to deployed product. The most comprehensive practical LLM course out there.
→ Agent Engineering Course — Hands on with production agent architectures, memory, routing, and eval frameworks — built from real enterprise engagements.
→ AI for Work — Understand, evaluate, and apply AI for complex work tasks.
Note: Article content contains the views of the contributing authors and not Towards AI.