![Semantic Search Engine Using Langchain Semantic Search Engine Using Langchain](https://i1.wp.com/miro.medium.com/v2/resize:fit:700/0*u0c9vt9bIPYVqibP.png?w=1920&resize=1920,1132&ssl=1)
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