-
Notifications
You must be signed in to change notification settings - Fork 37
examples n8n integration #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PredictiveManish
wants to merge
5
commits into
usemoss:main
Choose a base branch
from
PredictiveManish:n8n-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
abac26c
examples n8n integration
PredictiveManish 6406900
Added test and updated import design
PredictiveManish be97b8a
Potential fix for pull request finding
PredictiveManish 6a9066e
Added .env, updated README, json updates
PredictiveManish ca8c159
Merge branch 'n8n-integration' of https://github.com/PredictiveManish…
PredictiveManish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Moss Project Credentials | ||
| # Replace these values with your actual Moss project ID and project key | ||
| MOSS_PROJECT_ID=your-project-id-here | ||
| MOSS_PROJECT_KEY=your-project-key-here | ||
|
|
||
| # Optional: N8N specific configurations (if needed) | ||
| # N8N_HOST=http://localhost:5678 | ||
| # N8N_API_KEY=your-n8n-api-key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # Moss N8N Integration Cookbook | ||
|
|
||
| This cookbook provides a TypeScript helper and example workflow for integrating Moss with n8n, the open-source workflow automation platform. | ||
|
|
||
| ## Overview | ||
|
|
||
| The integration exposes Moss's core operations so any n8n workflow can incorporate real-time semantic search without writing SDK code from scratch: | ||
|
|
||
| - **Moss: Create Index** - Bootstrap a new index from an upstream data source | ||
| - **Moss: Add Documents** - Upsert one or more documents (with optional metadata) into an index | ||
| - **Moss: Delete Documents** - Remove documents by ID | ||
| - **Moss: Query** - Run a semantic/hybrid search query against an existing index | ||
|
|
||
| ## Files | ||
|
|
||
| 1. `moss-n8n-helper.ts` - A TypeScript wrapper around the Moss SDK optimized for n8n usage | ||
| 2. `n8n-moss-workflow.json` - An example n8n workflow demonstrating the four core operations | ||
| 3. `.env.example` - Example environment variables for Moss project credentials | ||
| 4. `test_moss_n8n_helper.ts` - Unit tests for the helper | ||
|
|
||
|
|
||
| ## Usage | ||
|
|
||
| ### Option 1: Using the TypeScript Helper (Recommended) | ||
|
|
||
| For the best developer experience, use the provided TypeScript helper in your n8n Function nodes: | ||
|
|
||
| 1. Copy `moss-n8n-helper.ts` to your n8n custom nodes directory or bundle it with your workflow | ||
| 2. Import and use it in Function nodes: | ||
|
|
||
| ```typescript | ||
| // Import the helper (adjust path as needed) | ||
| import { MossN8NHelper } from './moss-n8n-helper'; | ||
|
|
||
| // Initialize with your Moss credentials | ||
| const helper = new MossN8NHelper('your-project-id', 'your-project-key'); | ||
|
|
||
| // Create an index | ||
| const createResult = await helper.createIndex('my-index', [ | ||
| { id: '1', text: 'Hello world', metadata: { source: 'example' } } | ||
| ]); | ||
|
|
||
| // Check creation status (optional) | ||
| const createStatus = await helper.getJobStatus(createResult.jobId); | ||
|
|
||
| // Add docs | ||
| const addResult = await helper.addDocs('my-index', [ | ||
| { id: '2', text: 'Another document', metadata: { source: 'example' } } | ||
| ]); | ||
|
|
||
| // Load index for fast local queries (recommended before querying) | ||
| await helper.loadIndex('my-index'); | ||
|
|
||
| // Query | ||
| const results = await helper.query('my-index', 'hello', { topK: 5 }); | ||
|
|
||
| // Delete docs | ||
| const deleteResult = await helper.deleteDocs('my-index', ['1']); | ||
|
|
||
| // Clean up | ||
| helper.close(); | ||
| ``` | ||
|
|
||
| ### Option 2: Direct HTTP Requests | ||
|
|
||
| If you prefer not to use the helper, you can call Moss's public REST endpoints directly using n8n's HTTP Request nodes. Refer to the [Moss API documentation](https://docs.moss.dev) for endpoint details. | ||
|
|
||
| ## Environment Setup | ||
|
|
||
| 1. Copy `.env.example` to `.env` | ||
| 2. Replace the placeholder values with your actual Moss project ID and project key | ||
| 3. Never commit your actual `.env` file to version control | ||
|
|
||
| ## Example Workflow | ||
|
|
||
| The included `n8n-moss-workflow.json` demonstrates a complete workflow: | ||
|
|
||
| 1. **Start** - Manual trigger to begin the workflow | ||
| 2. **Moss Config** - Function node to set up Moss credentials | ||
| 3. **Create Moss Index** - Function node showing how to create an index | ||
| 4. **Add Documents** - Function node showing how to add documents | ||
| 5. **Query Moss Index** - Function node showing how to query the index | ||
| 6. **Delete Documents** - Function node showing how to delete documents | ||
|
|
||
| Note: The example workflow uses Function nodes to illustrate the logic. In a real implementation, you would replace the placeholder code with actual calls to the Moss N8N Helper. | ||
|
|
||
| ## Common Use Cases | ||
|
|
||
| ### Real-time Knowledge Base Sync | ||
| Pair n8n triggers (Google Drive, GitHub, Postgres, etc.) with the Moss "Add Documents" node to automatically keep a semantic index in sync with any upstream source. | ||
|
|
||
| ### RAG Pipelines Without Code | ||
| Feed data from various sources into a Moss index entirely within n8n workflows, then query it from AI agents or LLMs—no custom SDK code required. | ||
|
|
||
| ### AI Agent Workflows | ||
| Use the Moss query operation within AI agent chains to retrieve relevant context before generating responses. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Node.js >= 16 | ||
| - n8n >= 0.200.0 | ||
| - Moss account with project ID and project key | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Obtain your Moss project ID and project key from [Moss Dashboard](https://app.moss.dev) | ||
| 2. Install the Moss JavaScript SDK in your n8n environment (if using the helper approach): | ||
| ```bash | ||
| npm install @moss-dev/moss | ||
| ``` | ||
| 3. Set up your environment variables using the `.env.example` file | ||
| 4. Import the helper into your n8n Function nodes as shown above | ||
|
|
||
| ## Development | ||
|
|
||
| To modify the helper: | ||
| 1. Edit `moss-n8n-helper.ts` | ||
| 2. Run tests with: `npm test` (if you have a test setup) | ||
| 3. Test with your n8n instance | ||
|
|
||
| ## Demo | ||
|
|
||
| See `DEMO_SCRIPT.md` for a script to create a 1-minute demonstration video showing the integration in action. | ||
|
|
||
| ## License | ||
|
|
||
| BSD-2-Clause - See [LICENSE](../LICENSE) for details. | ||
|
PredictiveManish marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.