๐ Build a multi-tenant RAG search engine with Qdrant and OpenAI GPT-4o
โก 40 views ยท ๐ Internal Wiki & Knowledge Base
Description
Quick overview
This workflow exposes a POST webhook that authenticates a tenant, embeds the user query with OpenAI, searches tenant-scoped vectors in Qdrant, and uses GPT-4o to return a grounded answer with bracketed citations and usage metrics.
How it works
- Receives a POST request via a webhook with a user query and tenant identifiers (for example,
x-tenant-idin headers). - Validates that the tenant ID and query are present and routes invalid requests to an HTTP error response.
- Sends the query to OpenAI Embeddings (
text-embedding-3-small) to generate a vector. - Builds a Qdrant search request that enforces multi-tenant isolation using payload filters (required
tenant_id, optionalworkspace_idandcategory) and applies a similarity threshold. - Queries Qdrant for the top matching chunks, then formats the retrieved payload into a single context block and a structured citations list.
- Sends the query and formatted context to OpenAI Chat Completions (GPT-4o) to generate an answer that cites sources like [Source 1] using only the provided context.
- Assembles a final JSON response (answer, citations, similarity metrics, and token usage) and returns it to the webhook caller.
Setup
- Provide an OpenAI API key (used for embeddings and GPT-4o), either by setting
OPENAI_API_KEYas an environment variable or replacing the placeholder in the HTTP Authorization headers. - Set up a Qdrant instance and configure
QDRANT_HOST,QDRANT_API_KEY(if required), andQDRANT_COLLECTION(defaults toenterprise_rag_vectors). - Ensure your Qdrant collection stores payload fields used for filtering and citations (at minimum
tenant_id, and optionallyworkspace_id,category, plus fields likecontent/text,title/filename, anddocument_id). - Copy the webhook URL from the Webhook node and configure your client to POST a JSON body containing
queryand to includex-tenant-id(and optionallyx-workspace-id) headers.
Requirements
- โข OpenAI API Account (with text-embedding-3-small and GPT-4o access)
- โข Qdrant Cluster (Self-hosted Docker on VPS or Qdrant Cloud Free Tier)
- โข n8n instance (Cloud or Self-hosted v1.0+)
Customization
- โข Swap text-embedding-3-small with local Ollama / BGE embeddings for completely air-gapped on-premise deployments.
- โข Adjust the cosine similarity threshold (default 0.68) inside the Code node to fine-tune precision vs recall.
- โข Connect the output response to Slack, WhatsApp, or customer support chatbots for automated enterprise document search.
๐ Nodes Used
HTTP Request, Webhook
๐ฅ Import
Download workflow.json and import into n8n:
Workflow menu โ Import from File