
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
Take our 90+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!
Towards AI has published Building LLMs for Production—our 470+ page guide to mastering LLMs with practical projects and expert insights!

Discover Your Dream AI Career at Towards AI Jobs
Towards AI has built a jobs board tailored specifically to Machine Learning and Data Science Jobs and Skills. Our software searches for live AI jobs each hour, labels and categorises them and makes them easily searchable. Explore over 40,000 live jobs today with Towards AI Jobs!
Note: Content contains the views of the contributing authors and not Towards AI.