AI Knowledge base

2025-08-07

Reduce SOP friction, ask your own documentation for answers

Image for post

AI Knowledge Base with RAG

A Retrieval-Augmented Generation (RAG) system lets you ask questions against your own documentation instead of relying on generic AI answers. Imagine employees searching a SharePoint knowledge base and instantly getting accurate, AI-powered answers from your SOPs and internal articles.

This guide walks through setting up a simple RAG pipeline using your SharePoint site as the source of truth.


Why RAG?


Step 1: Extract documents from SharePoint

You’ll need a way to pull files and articles from your SharePoint site. Microsoft provides APIs and SDKs:

# Example using Microsoft Graph API
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root/children
Authorization: Bearer {token}

You can sync documents into a local folder or database, depending on how you want to process them.


Step 2: Chunk and embed your documents

Large documents need to be chunked into smaller sections (e.g., 500–1000 words) so the AI can retrieve precise context. Use an embedding model to convert each chunk into vectors:

from openai import OpenAI
from langchain.text_splitter import RecursiveCharacterTextSplitter
 
client = OpenAI()
 
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
chunks = text_splitter.split_text(document_text)
 
embeddings = [client.embeddings.create(input=chunk, model="text-embedding-3-small") for chunk in chunks]

Store these embeddings in a vector database (e.g., Postgres pgvector).


Step 3: Set up a vector database

A vector database allows fast similarity search. For example, with Postgres + pgvector:

CREATE EXTENSION IF NOT EXISTS vector;
 
CREATE TABLE documents (
  id SERIAL PRIMARY KEY,
  content TEXT,
  embedding vector(1536)
);

Insert your embeddings, and you can now query for the most relevant SOP snippets.


Step 4: Build the RAG pipeline

When a user asks a question:

  1. Convert the query into an embedding.
  2. Search your vector database for the most relevant chunks.
  3. Pass those chunks into the AI model as context.

Example with LangChain:

from langchain.chains import RetrievalQA
 
qa = RetrievalQA.from_chain_type(
    llm=client.chat.completions,
    retriever=vectorstore.as_retriever()
)
 
response = qa.run("How do I reset a user password?")
print(response)

Step 5: Deploy a user interface

Employees don’t want to see APIs—they want answers. You can expose the RAG pipeline via:


Step 6: Keep it fresh

A good knowledge base pipeline should stay up to date:


That wraps it up

With this setup, employees can finally stop scrolling through outdated SOP PDFs and instead just ask:

“How do we handle an urgent escalation?”

The AI answers—grounded in your documentation.