-
-
Notifications
You must be signed in to change notification settings - Fork 2
plugin plugin retrieval
Hybrid retrieval plugin for nSelf. Combines pgvector ANN and tsvector BM25 using Reciprocal Rank Fusion (RRF) to produce ranked results that outperform either method alone. Powers the search and recall tools in nself-ai-mcp.
Port: 3825 | License: Pro | Bundle: ɳClaw (AI-CP)
Reciprocal Rank Fusion merges multiple ranked lists into one. The score for each document:
rrf_score = Σ 1 / (k + rank) for each list containing the document
Where k = 60 (standard smoothing constant, Cormack et al. 2009).
| Scenario | Score |
|---|---|
| Document at rank 1 in one list | 1/(60+1) = 0.01639 |
| Document at rank 1 in both lists | 2 × 0.01639 = 0.03279 |
| Document at rank 5 in one list | 1/(60+5) = 0.01538 |
Documents found by both retrieval methods rank higher. Documents found by only one method still appear in the merged list. The fusion consistently outperforms single-method retrieval for mixed semantic + keyword queries.
- Index type: IVFFlat with cosine distance (
<=>operator) - Dimensions: 1536 (compatible with OpenAI ada-002, Anthropic embeddings)
- Embedding provided by caller — plugin does NOT call any AI provider (SSRF N/A)
- Returns documents sorted by cosine similarity descending
- Uses Postgres built-in
to_tsvector+plainto_tsquerywith English dictionary - Ranked by
ts_rank_cd(document coverage weighting) - No external dependencies — pure Postgres
Run hybrid search. Provide embedding for vector, query for text, or both for full hybrid.
Request:
{
"query": "semantic memory retrieval",
"embedding": [0.1, 0.2, 0.3],
"top_k": 10,
"source_account_id": "primary"
}Response:
{
"results": [
{
"id": "doc-abc",
"source_account_id": "primary",
"title": "Memory retrieval architecture",
"content": "...",
"similarity": 0.92,
"text_rank": 0.15,
"rrf_score": 0.032
}
],
"count": 5
}Fields:
-
similarity— pgvector cosine similarity (1 = identical), present if vector search ran -
text_rank— tsvector ts_rank_cd score, present if text search ran -
rrf_score— final merged score (higher = better match)
Results are always sorted by rrf_score descending.
Upsert a document and its embedding into the retrieval index.
Request:
{
"id": "memory-2026-01-15",
"title": "Meeting notes Jan 15",
"content": "Discussed retrieval architecture and RRF fusion approach...",
"embedding": [0.1, 0.2, 0.3],
"source_account_id": "primary"
}embedding is optional. If omitted, only text search will find this document.
Response: {"status":"indexed"} (201 Created)
Uses ON CONFLICT (id, source_account_id) DO UPDATE — safe to call repeatedly.
GET /health
→ {"status": "ok"} 200 — DB reachable
→ {"status": "unhealthy"} 503 — DB unavailable
Every query and index operation requires source_account_id. If not provided, defaults to
"primary". This enforces Multi-App Isolation: tenants never see each other's documents.
Hasura row filters on both np_retrieval_documents and np_retrieval_embeddings enforce
source_account_id = X-Hasura-Source-Account-Id for nself_user role.
nself license set <your-key>
nself plugin install plugin-retrievalSet required environment variables:
nself plugin env set plugin-retrieval NSELF_DB_URL=postgres://...
nself plugin env set plugin-retrieval NSELF_LICENSE_KEY=<your-key>Postgres must have the pgvector extension available:
CREATE EXTENSION IF NOT EXISTS vector;The plugin runs migrations automatically on startup.
| Variable | Required | Default | Description |
|---|---|---|---|
NSELF_DB_URL |
Yes | — | PostgreSQL connection string |
NSELF_LICENSE_KEY |
Yes | — | nSelf Pro license key |
NSELF_RETRIEVAL_PORT |
No | 3825 |
HTTP server port |
| Table | Purpose |
|---|---|
np_retrieval_documents |
Full text corpus with tsvector GIN index |
np_retrieval_embeddings |
Embedding vectors with IVFFlat cosine index |
Both tables use composite primary key (id, source_account_id) for clean tenant isolation.
The FK from np_retrieval_embeddings to np_retrieval_documents cascades on delete.
- IVFFlat
lists=100is tuned for up to ~1M vectors per account - For >1M vectors per account, increase
liststosqrt(row_count)and runREINDEX - Text search performance scales with
contentlength; chunk at ~512 tokens for best results - RRF fusion runs in memory (Go) — no additional DB round-trip
Requires an active nSelf Pro license. Purchase at nself.org/pro.
- plugin-nself-ai-mcp — uses this plugin for search and recall tools
- plugin-nself-ai-gateway — AI key pool for embedding generation
- Architecture
- Home
ɳSelf CLI v1.0.9. MIT licensed. Docs CC BY 4.0.
GitHub · Issues · Discussions · nself.org · docs.nself.org
Getting Started
Commands
- Commands, Overview
- Lifecycle: cmd-init · cmd-build · cmd-start · cmd-stop · cmd-restart · cmd-dev
- Monitoring: cmd-status · cmd-logs · cmd-health · cmd-urls · cmd-doctor · cmd-monitor · cmd-alerts · cmd-sentry · cmd-watchdog · cmd-dogfood
- Data: cmd-db · cmd-backup · cmd-dr · cmd-queue · cmd-webhooks
- Config: cmd-config · cmd-service · cmd-env · cmd-promote
- Networking: cmd-ssl · cmd-trust · cmd-dns-setup
- Security: cmd-security · cmd-secrets · cmd-waf
- Tenancy: cmd-tenant · cmd-billing
- Plugins: cmd-plugin · cmd-license
- AI: cmd-ai · cmd-claw · cmd-model
- Templates: cmd-template
- Utilities: cmd-exec · cmd-clean · cmd-reset · cmd-update · cmd-upgrade · cmd-version · cmd-admin · cmd-migrate · cmd-migrate-firebase · cmd-migrate-supabase · cmd-completion
Features
- Features, Overview
- Feature-Auth
- Feature-Storage
- Feature-Search
- Feature-Functions
- Feature-Email
- Feature-Monitoring
- Feature-Plugins
- Feature-ɳClaw, AI Assistant
- Feature-ɳChat, Messaging
- Feature-ɳTV, Media Player
- Feature-ɳFamily, Family Social
- Feature-ɳCloud, Managed Hosting
- Feature-Memory-Rooms, Knowledge Organization
- Feature-Agent-Dashboard, Agent Metrics
- Feature-Image-Generation, AI Image Generation
Configuration
- Configuration, Overview
- Config-Env-Vars
- Config-Postgres
- Config-Hasura
- Config-Auth
- Config-Nginx
- Config-Optional-Services
- Config-Custom-Services
- Config-System
Plugins (87 + 10 monitoring)
Free (25)
- plugin-backup
- plugin-content-acquisition
- plugin-content-progress
- plugin-cron
- plugin-donorbox
- plugin-feature-flags
- plugin-github
- plugin-github-runner
- plugin-invitations
- plugin-jobs
- plugin-link-preview
- plugin-mdns
- plugin-mlflow
- plugin-monitoring
- plugin-notifications
- plugin-notify
- plugin-paypal
- plugin-search
- plugin-shopify
- plugin-stripe
- plugin-subtitle-manager
- plugin-tokens
- plugin-torrent-manager
- plugin-vpn
- plugin-webhooks
Pro (62)
- plugin-access-controls
- plugin-activity-feed
- plugin-admin-api
- nself-ai-gateway
- nself-ai-cc
- nself-ai-mcp
- plugin-analytics
- plugin-auth
- plugin-backup-pro
- plugin-bots
- plugin-browser
- plugin-calendar
- plugin-cdn
- plugin-chat
- plugin-claw
- plugin-claw-budget
- plugin-claw-news
- plugin-claw-web
- plugin-cloudflare
- plugin-cms
- plugin-compliance
- plugin-cron-pro
- plugin-ddns
- plugin-devices
- plugin-documents
- plugin-donorbox-pro
- plugin-entitlements
- plugin-epg
- plugin-file-processing
- plugin-game-metadata
- plugin-geocoding
- plugin-geolocation
- plugin-google
- plugin-home
- plugin-idme
- plugin-knowledge-base
- plugin-linkedin
- plugin-livekit
- plugin-media-processing
- plugin-meetings
- plugin-moderation
- plugin-mux
- plugin-notify-pro
- plugin-object-storage
- plugin-observability
- plugin-paypal-pro
- plugin-photos
- plugin-podcast
- plugin-post
- plugin-realtime
- plugin-recording
- plugin-retro-gaming
- plugin-rom-discovery
- plugin-shopify-pro
- plugin-social
- plugin-sports
- plugin-stream-gateway
- plugin-streaming
- plugin-stripe-pro
- plugin-support
- plugin-tmdb
- plugin-voice
- plugin-web3
- plugin-workflows
Planned (26)
plugin-auditplugin-blogplugin-checkoutplugin-commerceplugin-drmplugin-exportplugin-flowplugin-importplugin-ldapplugin-mailgunplugin-mediaplugin-oauth-providersplugin-pagesplugin-postmarkplugin-rate-limitplugin-reportsplugin-samlplugin-schedulerplugin-sendgridplugin-ssoplugin-subscriptionplugin-thumbplugin-transcoderplugin-twilioplugin-wafplugin-watermark
Guides
- Guide-Production-Deployment
- Guide-SSL-Setup
- Guide-Multi-Tenancy
- Guide-Security-Hardening
- Guide-Monitoring-Setup
- Guide-Backup-Restore
- Guide-Custom-Services
- Guide-Migration-from-v1
Architecture
Reference
- API-Reference
- reference-error-codes, Error Codes
Licensing
Security
Brand
Operations
- operations/release-cascade, Release Cascade
- operations/self-healing, Self-Healing Schema
- operations/redis-tuning, Redis Pool Tuning
- operations/meilisearch-warmup, MeiliSearch Warm-Up
- operations/jwt-rotation, JWT Key Rotation
- operations/windows-wsl2-setup, Windows / WSL2 Setup
- operations/gemini-oauth-reauth, Gemini OAuth Reauth
Contributing
Admin
- USER-ACTION-QUEUE, Pending Admin Actions