An open API service indexing awesome lists of open source software.

https://github.com/yash-learnerr/pdf-chat-assistant

Build a powerful PDF Chat Assistant using Node.js, LangChain, and Google Gemini. Upload PDFs, extract content, and interact with them using natural language queries powered by Gemini LLM. Ideal for document Q&A, contract analysis, resume review, and more.
https://github.com/yash-learnerr/pdf-chat-assistant

ai-chatbot ai-pdf-reader document-ai document-qa gemini-api google-gemini google-llm langchain langchain-nodejs llm-backend nodejs-llm openai-alternative pdf-chat-assistant pdf-chat-node pdf-chatbot pdf-question-answering rag semantic-search

Last synced: about 2 months ago
JSON representation

Build a powerful PDF Chat Assistant using Node.js, LangChain, and Google Gemini. Upload PDFs, extract content, and interact with them using natural language queries powered by Gemini LLM. Ideal for document Q&A, contract analysis, resume review, and more.

Awesome Lists containing this project

README

          

# πŸ“„ PDF Chat Assistant using Node.js + LangChain + Google Gemini

**Chat with your PDFs using AI!** This open-source project lets you upload any PDF file and ask natural language questions about its content using **Google Gemini LLM**, **LangChain**, and **Node.js**.

> Ideal for document analysis, contract review, resume Q&A, and building AI-powered document search systems.

---

## ⭐ Features

- Upload PDF files and parse content.
- Chunk and embed text using **Gemini Embeddings**.
- Store embeddings in-memory using LangChain’s `MemoryVectorStore`.
- Perform similarity search on user questions.
- Query **Google Gemini** to generate accurate contextual responses.

## πŸš€ **Powered by**:

`Google Gemini`, `LangChain`, `FAISS`, `Express.js`, and `pdf-parse`

## πŸ“š **Keywords**:

`PDF Chat Assistant`, `LangChain Node.js`, `Gemini LLM`, `Document Q&A`, `RAG`, `AI Chatbot`, `PDF Parser`, `Semantic Search`

---

## 🧰 Tech Stack

| Component | Technology |
|----------------|-----------------------------|
| Backend | Node.js (Express) |
| AI/LLM API | Google Gemini (via LangChain)|
| PDF Parsing | `pdf-parse` |
| Embedding Store | LangChain Memory Vector DB |
| Chunking | Manual with configurable size |

---

## πŸ› οΈ Installation

```bash
git clone https://github.com/your-username/pdf-chat-gemini.git
cd pdf-chat-gemini
npm install

```

## πŸ” Environment Variables

Create a .env file in the root:

```
PORT=3000
GEMINI_API_KEY=your_google_gemini_api_key
```

##### βœ… You need access to Google AI Studio or Vertex AI to get your Gemini API key.

## πŸ“¦ Run the Project

```
node app.js
```

## πŸ“¬ API Endpoints

### 1. Upload PDF

```
POST /api/chat/upload
Content-Type: multipart/form-data
Form field: pdf (upload a .pdf file)
```

- Parses PDF
- Extracts text
- Chunks and embeds it into memory

### 2. Ask a Question

```
POST /api/chat/ask
Content-Type: application/json

{
"question": "What is this PDF about?"
}
```

- Returns answer based on the most relevant chunks from the uploaded PDF

#

## πŸ“ Project Structure

```
pdf-chat-assistant/
β”œβ”€β”€ app.js
β”œβ”€β”€ .env
β”œβ”€β”€ controllers/
β”‚ └── chatController.js
β”œβ”€β”€ routes/
β”‚ └── chatRoutes.js
β”œβ”€β”€ services/
β”‚ β”œβ”€β”€ pdfService.js
β”‚ β”œβ”€β”€ embeddingService.js
β”‚ └── geminiService.js
β”œβ”€β”€ utils/
β”‚ └── chunkText.js
β”œβ”€β”€ uploads/
└── vector-store/
```

## 🧠 How It Works

- Upload: PDF gets parsed and split into chunks.
- Embed: Each chunk is turned into a vector using Gemini Embeddings.
- Store: Vectors are stored in a temporary in-memory vector store.
- Query: User asks a question β†’ similar chunks are retrieved.
- Answer: Gemini responds using those chunks as context.

## πŸ§ͺ Example Usage

Use Postman or Insomnia to:

1. Upload a PDF to `/api/chat/upload`

2. Then POST to `/api/chat/ask` with your question

## Demo Link

[Demo](https://jam.dev/c/b569bc2b-6417-49ad-87ce-5672bbc63a22)

## πŸ“„ License
MIT License

## πŸ™Œ Acknowledgements
LangChain

Google Generative AI (Gemini)

pdf-parse