npm package: @matheusprm-nodes/n8n-nodes-tool-vector-store-custom-prompt
Description: n8n community node for Vector Store QA Tool with customizable prompt
Author: matheusprm
Latest version: 0.1.9

# n8n-nodes-tool-vector-store-custom-prompt

[![npm version](https://img.shields.io/npm/v/n8n-nodes-tool-vector-store-custom-prompt.svg)](https://www.npmjs.com/package/n8n-nodes-tool-vector-store-custom-prompt)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A custom n8n community node that extends the Vector Store Question Answer Tool with **editable prompt templates**. This node allows you to customize the QA prompt used in RAG (Retrieval-Augmented Generation) workflows, providing more control over how AI agents answer questions using vector stores.

## Features

- ✅ **Customizable Prompt Template** - Edit the QA prompt via UI (unlike the original node)
- ✅ **Two Prompt Modes** - Support for both "stuff" (PromptTemplate) and "chat" (ChatPromptTemplate) modes
- ✅ **Strict Mode** - Prevents AI from making inferences and requires explicit evidence from context
- ✅ **Source Return** - Optional return of document sources with metadata
- ✅ **Full LangChain Integration** - Uses VectorDBQAChain with StuffDocumentsChain
- ✅ **AI Tool Compatible** - Works seamlessly with n8n AI Agents

## Installation

Install this node in your n8n instance:

```bash
npm install n8n-nodes-tool-vector-store-custom-prompt
```

## Usage

### Basic Setup

1. Add the **Vector Store QA Tool (Custom Prompt)** node to your workflow
2. Connect a **Vector Store** node to the first input
3. Connect a **Language Model** (Chat Model) to the second input
4. Configure the node parameters:
   - **Description**: Describe what data is in your vector store (e.g., "imóveis, bairros e empreendimentos")
   - **Limit (Top-K)**: Number of documents to retrieve (default: 4)
   - **Prompt Template**: Your custom QA prompt (must include `{context}` and `{question}`)
   - **Strict Mode**: Enable to prevent AI inferences (recommended)

### Connecting to AI Agent

1. Add an **AI Agent** node to your workflow
2. Enable the tool from the Vector Store QA Tool node
3. The tool will be available with a sanitized name based on your node name

### Example Prompt Template

```
Você é um assistente de QA (perguntas e respostas) que responde com base APENAS no contexto fornecido.

REGRAS CRÍTICAS:
1) Use SOMENTE as informações presentes no CONTEXTO.
2) Se a resposta não estiver explicitamente no CONTEXTO, responda exatamente: "Não encontrei essa informação no contexto disponível."
3) NÃO inferir bairros/regiões próximas, "na região", "perto de", "equivalentes" ou similares, a menos que o CONTEXTO cite isso explicitamente.
4) NÃO inventar códigos/IDs de imóveis e NÃO supor características que não estejam no CONTEXTO.
5) Se a pergunta exigir filtros (ex.: bairro X, 3 quartos, 2 vagas), só traga itens que tenham esses critérios explícitos no CONTEXTO.

CONTEXTO:
{context}

PERGUNTA:
{question}

RESPONDA de forma direta, curta e objetiva.
```

## Node Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| **Description** | string | "imóveis, bairros e empreendimentos" | Description of the vector store content (used in tool description) |
| **Limit (Top-K)** | number | 4 | Maximum number of documents to retrieve in similarity search |
| **Prompt Mode** | options | "stuff" | Prompt mode: "stuff" (PromptTemplate) or "chat" (ChatPromptTemplate) |
| **Document Variable Name** | string | "context" | Variable name in template that receives the context (must match `{context}` in prompt) |
| **Strict Mode** | boolean | true | When enabled, injects reinforcements to prevent inference and require explicit evidence |
| **Return Sources** | boolean | false | When enabled, returns a SOURCES section with document metadata |
| **Prompt Template** | string | (see default above) | Editable prompt used to combine documents from vector store |

## Differences from Original Node

| Aspect | Original `toolVectorStore` | This Node |
|--------|---------------------------|-----------|
| Prompt | Fixed LangChain default (not editable) | **Editable via UI** |
| Customization | Limited | Full control over instructions, tone, response format |
| Use Cases | Generic | Specific business needs (e.g., real estate, internal docs) |

## Requirements

- **n8n**: Version 1.0.0 or higher
- **langchain**: ^0.3.0 (peer dependency)
- **@langchain/core**: ^0.3.0 (peer dependency)

## Development

### Prerequisites

- Node.js v22 or higher
- npm

### Setup

```bash
# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode
npm run dev

# Lint code
npm run lint
```

## Troubleshooting

### Node doesn't appear in n8n

1. Make sure you ran `npm install`
2. Check that the node is listed in `package.json` under `n8n.nodes`
3. Restart n8n
4. Check console for error messages

### "Cannot find module 'langchain'"

This usually means langchain dependencies are not installed. Ensure you have:
- `langchain` ^0.3.0
- `@langchain/core` ^0.3.0

These should be available in your n8n environment.

### Invalid prompt template

The node validates that your prompt template includes:
- `{context}` (or the name configured in "Document Variable Name")
- `{question}` (required in "stuff" mode)

Make sure both placeholders are present in your template.

## License

[MIT](LICENSE.md)

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Support

For issues and questions:
- [n8n Community Forum](https://community.n8n.io/)
- [GitHub Issues](https://github.com/n8n-io/n8n-nodes-starter/issues)

## Related

- [n8n Documentation](https://docs.n8n.io/)
- [LangChain Documentation](https://js.langchain.com/)
- [n8n Community Nodes](https://www.npmjs.com/search?q=keywords:n8n-community-node-package)