Company RAG and data queries

Pinecone RAG workflow with structured output and source citations

Short answer

This n8n workflow attaches file_name and file_url metadata to Google Drive chunks before storing them in Pinecone. On each chat question, it fetches the top matching chunks, formats numbered context blocks and constrains OpenAI with a structured schema returning answer text plus exact citation numbers mapped to URLs.

Catalogue ID
#1376
Functional nodes
18
Connections
16
Trigger
manualTrigger, chatTrigger
AI layer
AI-assisted
Business problem solved

Business problem solved

Unstructured RAG answers rarely show which file or passage backed a claim, leaving legal, finance and compliance teams unable to audit replies. Asking a model to type URLs freehand also risks fabricated links.

Trigger

A manual trigger indexes Drive files with metadata, while a chat trigger drives cited Q&A.

Connected systems

Connected systems

  • Google Drive
  • Pinecone vector store
  • OpenAI
  • Structured output parser
  • Code metadata and citation formatter
  • Self-hosted n8n

Every workflow is deployed on your own server with documentation, a run log and an error queue.

Workflow architecture

Workflow architecture

  1. 1. When clicking Execute… (Trigger) (connects to Set file URL in Google Drive)
  2. 2. Embeddings OpenAI (AI layer) (connects to Add to Pinecone vector store)
  3. 3. Default Data Loader (AI layer) (connects to Add to Pinecone vector store)
  4. 4. Set file URL in Google Drive (Service and data) (connects to Download file)
  5. 5. Add in metadata (Logic and routing) (connects to Add to Pinecone vector store)
  6. 6. Download file (Service and data) (connects to Add in metadata)
  7. 7. Chat Trigger (Trigger) (connects to Set max chunks to send to…)
  8. 8. Prepare chunks (Logic and routing) (connects to Answer the query based on…)
  9. 9. Embeddings OpenAI2 (AI layer) (connects to Get top chunks matching…)
  10. 10. OpenAI Chat Model (AI layer) (connects to Answer the query based on…)
  11. 11. Set max chunks to send to… (Service and data) (connects to Get top chunks matching…)
  12. 12. Structured Output Parser (AI layer) (connects to Answer the query based on…)
  13. 13. Compose citations (Service and data) (connects to Generate response)
  14. 14. Generate response (Service and data)
  15. 15. Answer the query based on… (AI layer) (connects to Compose citations)
  16. 16. Get top chunks matching… (AI layer) (connects to Prepare chunks)
  17. 17. Add to Pinecone vector store (AI layer)
  18. 18. Recursive Character Text… (AI layer) (connects to Default Data Loader)
  • Trigger
  • AI layer
  • Logic and routing
  • Service and data

Node positions and directed links are generated from the verified catalogue record.

Workflow steps

Workflow steps

  1. 01

    Drive fetch and metadata tagging

    A Code node extracts file name and extension from Drive and attaches source URL metadata to every Pinecone chunk.

  2. 02

    Top-K chunk retrieval and numbering

    Chat queries set chunk limits, load matching Pinecone chunks and format numbered context blocks in Code.

  3. 03

    Structured answer and citation schema

    The LLM chain paired with a structured output parser outputs the answer string plus an array of cited chunk indexes.

  4. 04

    Programmatic citation link assembly

    Set nodes map returned chunk indexes back to verified Drive URLs and append citations under the answer.

Error queue and human approval

Error queue and human approval

Built-in state in the catalogue workflow

The verified catalogue workflow contains zero node-level error flags, while schema parsing and index mapping enforce verifiable citations.

Production layer added by ALTAI

During live deployment, ALTAI blocks uncited claims when context lacks an answer, purges stale file vectors on updates and logs parser errors to an alert queue.

Frequently asked

Pinecone cited structured RAG Frequently asked questions

No. The model only returns integer chunk indexes; actual file names and URLs are resolved programmatically from Pinecone metadata.

Yes. A dedicated parameter node sets the chunk limit before retrieval so depth balances easily against token cost.

The prompt instructs the model to state that the answer is unknown and leaves the citation list empty.

Mert Can Gundogdu
The founder takes the call, not a sales team
Next step

We write the proposal after we have found the problem together

In a thirty-minute call we listen to how you work and talk through where time and customers are slipping away. If you do not need a digital fix, we will tell you that too.

30 minutes · no preparation needed

The call and the week of discovery are both free.Read the terms

Chat on WhatsApp