npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

n8n-nodes-source-documents-retriever-qa-chain

v1.1.3

Published

A custom n8n node for question-answering using retrieved documents, with optional source document output for enhanced traceability and transparency.

Downloads

215

Readme

Get the Source Documents from the Q&A Chain Agent

Custom n8n Node for Question-Answering with Source Document Output


Overview

n8n-nodes-chain-retrieval-qa is a custom n8n node that leverages the LangChain library to perform question-answering tasks using retrieved documents. This node includes an optional feature to output the source documents that contributed to the response, providing enhanced traceability and transparency.

Features

  • Question Answering: Ask questions based on retrieved documents.
  • Source Document Output: Enable optional output of source documents for better traceability.
  • Integration with LangChain: Uses LangChain's Retrieval QA Chain for powerful retrieval and response generation.

Add to Your n8n Setup

  1. Place the installed package into your n8n custom node directory.
  2. Restart your n8n instance to load the new node.

Usage

Input

This node requires two inputs:

  1. Model: A language model for generating responses (e.g., OpenAI, HuggingFace).
  2. Retriever: A retriever to fetch relevant documents from a data source.

Parameters

  • Query: The question or input for the QA system.
  • Return Source Documents: Enable this option to include the documents that contributed to the response in the output.
  • Options:
    • System Prompt Template: Customize the system prompt for context-aware responses.

Output

The output includes:

  1. Response: The generated answer to the query.
  2. Source Documents (optional): An array of documents used to generate the response (if enabled).

Examples

Example Workflow

  1. Add the Question and Answer Chain with Source Documents node to your workflow.
  2. Connect it to:
    • A language model node (e.g., OpenAI or HuggingFace).
    • A retriever node for fetching relevant documents.
  3. Configure the parameters as needed.

Example Output

{
	"response": "n8n is a powerful workflow automation tool.",
	"documents": [
		{ "content": "n8n is an open-source workflow automation tool." },
		{ "content": "It allows users to automate tasks across various services." }
	]
}

n8n Node example:

{
	"nodes": [
		{
			"parameters": {
				"options": {}
			},
			"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
			"typeVersion": 1,
			"position": [80, -140],
			"id": "fe2997f6-f581-419d-be40-ff85fac3b6e8",
			"name": "OpenAI Chat Model",
			"credentials": {
				"openAiApi": {
					"id": "7KA1OCyTLjMmwqUx",
					"name": "OpenAi account"
				}
			}
		},
		{
			"parameters": {},
			"type": "@n8n/n8n-nodes-langchain.retrieverVectorStore",
			"typeVersion": 1,
			"position": [260, -120],
			"id": "cc94a29c-8b8f-4fbc-b7bf-0f3df0fc8b02",
			"name": "Vector Store Retriever"
		},
		{
			"parameters": {
				"options": {}
			},
			"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
			"typeVersion": 1.1,
			"position": [480, 100],
			"id": "77a18ee1-8586-48a0-b4b9-f7bd0b9582b6",
			"name": "Embeddings OpenAI",
			"credentials": {
				"openAiApi": {
					"id": "7KA1OCyTLjMmwqUx",
					"name": "OpenAi account"
				}
			}
		},
		{
			"parameters": {},
			"type": "n8n-nodes-base.executeWorkflowTrigger",
			"typeVersion": 1,
			"position": [-220, -520],
			"id": "92dae8a6-d6b7-4ae5-b5d6-4cc58d743208",
			"name": "Execute Workflow Trigger"
		},
		{
			"parameters": {
				"options": {}
			},
			"type": "CUSTOM.chainRetrievalQaWithSourceDocuments",
			"typeVersion": 1.4,
			"position": [120, -520],
			"id": "097833c9-30cf-4786-b50a-32f3ecc9a651",
			"name": "Question and Answer Chain With Source Documents"
		}
	],
	"connections": {
		"OpenAI Chat Model": {
			"ai_languageModel": [
				[
					{
						"node": "Question and Answer Chain With Source Documents",
						"type": "ai_languageModel",
						"index": 0
					}
				]
			]
		},
		"Vector Store Retriever": {
			"ai_retriever": [
				[
					{
						"node": "Question and Answer Chain With Source Documents",
						"type": "ai_retriever",
						"index": 0
					}
				]
			]
		},
		"Embeddings OpenAI": {
			"ai_embedding": [[]]
		},
		"Execute Workflow Trigger": {
			"main": [
				[
					{
						"node": "Question and Answer Chain With Source Documents",
						"type": "main",
						"index": 0
					}
				]
			]
		}
	},
	"pinData": {
		"Execute Workflow Trigger": [
			{
				"query": {
					"message": "Are there any one bedroom apartment?"
				}
			}
		]
	}
}

Development

Prerequisites

  • Node.js >= 18.10
  • pnpm >= 9.1

Clone and Build

  1. Clone the repository:
    git clone https://github.com/leonardogrig/n8n-metadata-chain-retrieval-qa.git
    cd n8n-metadata-chain-retrieval-qa
  2. Install dependencies:
    pnpm install
  3. Build the project:
    pnpm build

License

This project is licensed under the MIT License. See the LICENSE file for details.


Author

Leonardo Grigorio Araujo
Email: [email protected]
GitHub: leonardogrig