Semantic Search Engine Using Langchain
towardsai.net
Semantic Search Engine Using Langchain 0 like February 5, 2025Share this postAuthor(s): Lo Zarantonello Originally published on Towards AI. Load and query a PDF locally using LangchainThis 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.Langchain ecosystemIn 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 runnode index.js Node doesnt 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 asponsor. Published via Towards AITowards AI - Medium Share this post
0 Commentarios ·0 Acciones ·60 Views