Quick Start
Get up and running in 5 minutes.
1. Set Up Credentials
In n8n, create Postgres credentials:
- Go to Credentials → Add Credential
- Search for Postgres
- Fill in your connection details:
| Field | Value |
|---|---|
| Host | Your PostgreSQL host |
| Port | 5432 (default) |
| Database | Your database name |
| User | Database user |
| Password | Database password |
| SSL | Configure as needed |
2. Initialize Schema
Before storing embeddings, initialize the database schema.
Add a PGVector Advanced node:
| Setting | Value |
|---|---|
| Operation | Admin |
| Admin Operation | Ensure Schema |
| Dimensions | 1536 (or your embedding size) |
This creates the embeddings table and necessary indexes if they don’t exist.
3. Store Your First Embedding
Add another PGVector Advanced node:
| Setting | Value |
|---|---|
| Operation | Upsert |
| Collection | my_documents |
| External ID | doc-001 |
| Content | “This is my first document” |
| Embedding | [0.1, 0.2, 0.3, …] |
| Metadata | {“category”: “test”} |
Tip: Use an OpenAI Embeddings node or similar to generate the embedding vector from your text.
4. Query Similar Documents
Add a PGVector Advanced node to search:
| Setting | Value |
|---|---|
| Operation | Query |
| Collection | my_documents |
| Query Embedding | [0.1, 0.2, …] |
| Top K | 10 |
| Distance Metric | cosine |
Results include:
id- Internal UUIDexternalId- Your stable IDcontent- Document textmetadata- JSON metadatascore- Similarity score (lower = more similar)
5. Complete Example Workflow
Here’s a typical semantic search workflow:
[HTTP Request] → [OpenAI Embeddings] → [PGVector Upsert]
↓
[Search Query Input]
↓
[OpenAI Embeddings] → [PGVector Query] → [Results]
Workflow Steps:
- Ingest documents
- Fetch documents (HTTP, file, database)
- Generate embeddings with OpenAI/Cohere
- Upsert to PGVector with metadata
- Search
- Receive search query
- Generate query embedding
- Query PGVector for similar documents
- Return results
Common Patterns
Upsert with External ID (Sync-Friendly)
{
"operation": "upsert",
"collection": "documents",
"externalId": "notion-page-abc123",
"content": "Page content here",
"metadata": {
"source": "notion",
"lastUpdated": "2024-01-15"
},
"embedding": [...]
}
Using externalId means:
- Re-running updates existing records (no duplicates)
- Easy to sync from external systems
- Stable references for your application
Batch Upsert
For bulk operations, use batch mode with field mapping:
{
"operation": "upsert",
"mode": "batch",
"collection": "documents",
"fieldMapping": {
"externalIdField": "id",
"contentField": "text",
"metadataField": "meta",
"embeddingField": "vector"
}
}
Input items:
[
{"id": "doc-1", "text": "First doc", "meta": {}, "vector": [...]},
{"id": "doc-2", "text": "Second doc", "meta": {}, "vector": [...]}
]
Query with Metadata Filter
{
"operation": "query",
"collection": "documents",
"queryEmbedding": [...],
"topK": 5,
"metadataFilter": {
"category": "technology",
"status": "published"
}
}
Next Steps
- Operations Reference - All operations in detail
- API Reference - Database schema and TypeScript API
- Troubleshooting - Common issues