Skip to main content

Add tenant-scoped semantic search to your app

SaaS search cannot be just “nearest documents.” Every query must respect tenant boundaries, roles, regions, and application-specific visibility rules. VectorAmp supports metadata filters so your backend can enforce scope before returning results.

What you will build

A Node.js backend route that receives a search request, applies server-side access filters, and queries VectorAmp.

Prerequisites

  • Node.js 18+.
  • A VectorAmp API key stored server-side.
  • Documents indexed with tenant and access metadata.

Step 1: Install the SDK

npm install @vectoramp/vectoramp

Step 2: Store searchable metadata

Every record should include access metadata. Example:

{
"tenant_id": "tenant_acme",
"region": "eu",
"visibility": "support",
"object_type": "ticket",
"created_year": 2026
}

Step 3: Implement a server-side search route

import { VectorAmp } from '@vectoramp/vectoramp';

const client = new VectorAmp({ apiKey: process.env.VECTORAMP_API_KEY });

export async function searchTenantKnowledge(req, res) {
const { query, region } = req.body;
const user = req.user;

if (!query || typeof query !== 'string') {
return res.status(400).json({ error: 'query is required' });
}

const dataset = await client.datasets.get(process.env.VECTORAMP_DATASET_ID);

const results = await dataset.search({
queryText: query,
topK: 10,
includeMetadata: true,
filter: {
tenant_id: user.tenantId,
visibility: user.supportScope,
...(region ? { region } : {})
}
});

return res.json({ results: results.results });
}

Step 4: Test access boundaries

Create tests that prove:

  • A user from tenant A cannot retrieve tenant B content.
  • Region filters restrict results.
  • Role filters restrict internal-only content.
  • Empty or invalid queries fail safely.

Step 5: Add richer retrieval controls

Once basic search works, add:

  • topK controls for result depth.
  • hybrid search for exact IDs and rare terms.
  • rerank for answer quality.
  • advanced_filters for numeric/date ranges where appropriate.

Python equivalent

from vectoramp import VectorAmp

client = VectorAmp(api_key="vsk_...")
dataset = client.datasets.get("ds_123")

results = dataset.search(
text="refund policy exception",
top_k=10,
filters={"tenant_id": "tenant_acme", "visibility": "support"},
include_documents=True,
)

Production notes

  • Never accept tenant_id from the browser as trusted input.
  • Apply access filters in your backend.
  • Keep API keys on the server.
  • Log search request IDs, not sensitive query text, unless your privacy policy allows it.