Prompt

How do I build a RAG chatbot over SharePoint and Google Drive?

Artificial Intelligence / AI Search1 observationLast seen Oct 10, 2026

Latest observation

Oct 10, 2026OpenAI APIWeb search: off

To build a RAG chatbot over SharePoint + Google Drive, think of it as 5 parts:

  1. Connect to the sources
  2. Extract and clean documents
  3. Chunk + embed + index
  4. Retrieve relevant chunks at question time
  5. Generate an answer with citations

Here’s a practical blueprint.


1) Architecture

Ingestion path

  • SharePoint connector → fetch files/pages
  • Google Drive connector → fetch files/docs
  • Text extraction/OCR → normalize content
  • Chunking → split into searchable passages
  • Embeddings → convert chunks to vectors
  • Indexing → store in vector DB + metadata store

Query path

  • User asks question
  • Query is embedded
  • Retrieve top-k relevant chunks from vector DB
  • Optionally filter by permissions, source, date, file type
  • LLM answers using retrieved context
  • Return citations/links back to SharePoint/Drive

2) Choose your stack

Common options

Ingestion / orchestration

  • Python
  • LangChain or LlamaIndex
  • Airflow / Prefect / Celery for scheduled syncs

Connectors

  • SharePoint / Microsoft Graph API
  • Google Drive API

Parsing

  • Unstructured
  • Apache Tika
  • Pandoc / pdfplumber / docx / python-pptx for specific formats

Vector DB

  • Pinecone, Weaviate, Qdrant, Milvus, pgvector, Elasticsearch/OpenSearch vector search

LLM / embeddings

  • OpenAI, Azure OpenAI, Anthropic, or open-source models
  • Sentence-transformers or hosted embedding models

3) Connect to SharePoint

Use Microsoft Graph API to access SharePoint content.

Typical steps:

  • Register an Azure app
  • Grant permissions like Sites.Read.All or least-privilege site-specific access
  • Use OAuth2 client credentials or delegated auth
  • Traverse:
    • Sites
    • Document libraries
    • Lists / pages if needed
  • Download files and capture metadata:
    • site_id
    • library/folder path
    • file_id
    • last_modified
    • owner
    • permissions

Important:

  • Respect tenant policies
  • Handle incremental sync using delta queries where possible
  • Cache auth tokens securely

4) Connect to Google Drive

Use the Google Drive API.

Typical steps:

  • Create a Google Cloud project
  • Enable Drive API
  • Use OAuth or service account with domain-wide delegation if needed
  • Traverse folders/files
  • Download native docs as exported text where appropriate:
    • Google Docs → text/HTML
    • Sheets → CSV/TSV or selected ranges
    • Slides → text export
    • PDFs/Office docs → raw file download
  • Capture metadata:
    • file_id
    • mime_type
    • path/folder
    • modified_time
    • permissions

Important:

  • Incremental sync via changes.list
  • Use shared drive support if applicable

5) Document extraction and normalization

You want a single internal text format.

For each file:

  • Detect type
  • Extract text
  • Preserve headings, tables, bullets if possible
  • Remove boilerplate
  • Store metadata and source URL

Examples:

  • PDF: pdfplumber, pymupdf, or OCR if scanned
  • DOCX: python-docx
  • PPTX: python-pptx
  • HTML/Pages: parse as structured text
  • Google Docs: export as plain text or HTML
  • Images/scans: OCR via Tesseract, Azure Document Intelligence, AWS Textract, or Google Document AI

Good practice:

  • Keep original file link
  • Keep page number / slide number / section name if available
  • Keep access control metadata

6) Chunking strategy

Split text into retrievable units.

Recommended:

  • Chunk by headings/paragraphs first
  • Aim for ~300–800 tokens per chunk
  • Use 10–20% overlap
  • Attach metadata:
    • source = SharePoint / Google Drive
    • document title
    • file URL
    • page number / section
    • modified date
    • ACL / groups

For long docs:

  • hierarchical chunking works well:
    • document summary
    • section chunks
    • paragraph chunks

7) Embeddings + vector index

For each chunk:

  • Generate embedding
  • Store in vector DB with metadata

Index design:

  • chunk_id
  • doc_id
  • text
  • embedding
  • metadata fields for filtering:
    • source system
    • tenant/site/folder
    • access groups
    • date
    • doc type

Optional:

  • Keep a keyword index too for hybrid search
  • Use BM25 + vector retrieval for better recall

8) Permission-aware retrieval

This is critical for enterprise RAG.

At query time:

  • Authenticate the user
  • Determine user groups / identity
  • Filter retrieval to chunks the user is allowed to see
  • Never send unauthorized chunks to the LLM

Implementation options:

  • Store ACL metadata per document/chunk
  • Filter in vector DB if supported
  • Or retrieve then post-filter before generation
  • Best is pre-filtering + security trimming

If you skip this, you risk data leakage.


9) Query flow

A solid query pipeline:

  1. User asks: “What’s our expense policy for international travel?”
  2. Embed query
  3. Retrieve:
    • top 10–30 chunks
    • optionally hybrid search
    • filter by permissions
  4. Re-rank results with a cross-encoder or LLM-based reranker
  5. Build prompt with:
    • question
    • retrieved passages
    • instructions to cite sources and not hallucinate
  6. LLM generates answer
  7. Return answer + citations + links

10) Prompting pattern

Use a constrained prompt like:

  • Answer only from provided context
  • If context is insufficient, say so
  • Cite sources per claim
  • Prefer recent policy docs when conflicts exist

Example instruction:

You are an enterprise assistant. Use only the provided context. If the answer is not in the context, say you don’t know. Include citations with document title and link.


11) Sync and updates

You need ongoing ingestion:

  • Schedule refresh every N minutes/hours
  • Use incremental change APIs:
    • SharePoint delta queries
    • Google Drive changes feed
  • Re-embed changed docs
  • Delete removed docs/chunks
  • Version documents if you need auditability

A common pattern:

  • Store document hash
  • Only reprocess if content changed
  • Maintain tombstones for deleted files

12) Evaluation

Test with real user questions:

  • Recall: did retrieval find the right chunks?
  • Precision: did it include irrelevant chunks?
  • Faithfulness: is the answer grounded in retrieved text?
  • Coverage: are the right sources indexed?
  • Permission correctness: can users only see allowed content?

Useful metrics:

  • top-k hit rate
  • answer correctness
  • citation accuracy
  • latency
  • ingestion freshness

13) Minimal implementation outline

Ingestion pseudocode

for source in [sharepoint, google_drive]:
    docs = source.list_changed_documents(since=last_sync)
    for doc in docs:
        raw = source.download(doc)
        text = extract_text(raw)
        chunks = chunk_text(text)
        embeddings = embed(chunks)
        vector_db.upsert([
            {
                "id": chunk.id,
                "vector": embeddings[i],
                "text": chunk.text,
                "metadata": doc.metadata
            }
            for i, chunk in enumerate(chunks)
        ])

Query pseudocode

user = authenticate()
query_vec = embed([question])[0]
results = vector_db.search(
    query_vec,
    top_k=10,
    filter={"acl": {"$in": user.groups}}
)
answer = llm.generate(question, results)
return answer

14) Recommended production architecture

If you want something robust:

  • API: FastAPI
  • Workers: Celery/RQ + Redis
  • Connectors: Microsoft Graph + Google Drive APIs
  • Parsing: Unstructured + OCR fallback
  • Storage:
    • object store for originals
    • Postgres for metadata
    • Qdrant/Weaviate/Pinecone for vectors
  • Auth: Azure AD / Google SSO / OIDC
  • Observability: logs, tracing, prompt/answer audit
  • Guardrails: permission checks, citation requirement, PII redaction if needed

15) Practical shortcuts

If you want to move fast, consider:

  • LlamaIndex has good connectors and RAG abstractions
  • LangChain has many integrations
  • Microsoft Graph connectors can simplify SharePoint access
  • Google Drive loader utilities are available in both ecosystems

But still verify:

  • permission handling
  • incremental sync
  • file-type extraction quality

16) Common pitfalls

  • Ignoring ACLs and leaking documents
  • Chunking too large or too small
  • Not preserving source metadata
  • Treating scanned PDFs as text-only
  • Using only vector search and missing keyword exact matches
  • Failing to handle duplicates and file versions
  • Not refreshing indexes after updates
  • No evaluation set before launch

17) Suggested MVP plan

Week 1

  • Connect SharePoint and Drive
  • Ingest a small set of docs
  • Build extraction + chunking
  • Store in vector DB

Week 2

  • Build retrieval + chat endpoint
  • Add citations
  • Add basic ACL filtering

Week 3

  • Incremental sync
  • Hybrid search
  • Evaluation with real questions

Week 4

  • Improve reranking
  • Add monitoring, admin tools, and audit logs

If you want, I can also give you:

  1. a reference architecture diagram,
  2. a Python starter project, or
  3. a specific implementation using LangChain/LlamaIndex + Pinecone/Qdrant + Microsoft Graph + Google Drive API.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.