DEV Community

Cover image for How docs AI search works: Mintlify-Style with OpenAI Agents SDK
Siddhant Khare
Siddhant Khare

Posted on

2 2 2 2 2

How docs AI search works: Mintlify-Style with OpenAI Agents SDK

Documentation remains a critical resource for developers, serving as the definitive guide and knowledge base for any software product or service. However, traditional keyword-based searches often fall short, delivering imprecise or irrelevant results. With the rise of Large Language Models (LLMs) and sophisticated AI solutions, semantic vector search has emerged as a powerful technology revolutionizing how developers interact with documentation.

In this deep, technical exploration, I will unravel how Docs AI search similar to Mintlify's feature works internally, emphasizing vector search powered by OpenAI's Agents SDK. I'll delve into the underlying mechanics, practical implementation, and specific developer-centric use cases.

Understanding Vector Search in Technical Context

Vector search represents textual data as numerical embeddings (vectors) capturing semantic meaning. Unlike conventional keyword-based search, vector search understands context and nuances, matching user queries to semantically similar documents rather than exact word matches.

Consider a developer query such as "How to deploy an app with Kubernetes?" Using vector embeddings, Docs AI returns relevant documents including terms like "app deployment," "Kubernetes orchestration," or even "containerized application launch."

Search query

Why Docs AI Searches Exclusively Within Provided Documentation

Docs AI intentionally limits searches strictly to user-provided documentation, prioritizing the following principles:

  • Precision: To provide highly accurate and contextually relevant answers directly from trusted sources.
  • Data Privacy & Security: Protects sensitive data by avoiding reliance on external information.
  • User Trust: Ensures consistent, reliable search outcomes without ambiguity from external sources.

Technical Implementation of Docs AI Using OpenAI's Agents SDK

Step 1: Initializing a Vector Store

The first step involves creating a dedicated vector store, acting as your semantic search knowledge base:

from openai import OpenAI

client = OpenAI()

vector_store = client.vector_stores.create(name="devops_docs")
print(f'Vector Store ID: {vector_store.id}')
Enter fullscreen mode Exit fullscreen mode

Store Id mapping

Step 2: Adding Documents to the Vector Store

Upload developer-focused documentation such as Kubernetes configuration guides, Docker best practices, or CI/CD pipeline examples:

import requests
from io import BytesIO

def upload_document(client, vector_store_id, target):
    if target.startswith(("http://", "https://")):
        response = requests.get(target)
        file_content = BytesIO(response.content)
        file_tuple = (target.split("/")[-1], file_content)
    else:
        file_tuple = open(target, "rb")

    file_id = client.files.create(file=file_tuple, purpose="assistants").id

    client.vector_stores.files.create(vector_store_id=vector_store_id, file_id=file_id)
    return file_id

file_id = upload_document(client, vector_store.id, "https://example.com/k8s-deployment.pdf")
Enter fullscreen mode Exit fullscreen mode

Upload docs flow

Step 3: Semantic Search with OpenAI's Agents SDK

Querying the vector store to retrieve precise, relevant results based on semantic understanding:

from agents import Agent, Runner, FileSearchTool

agent = Agent(
    name="DevOpsAgent",
    tools=[
        FileSearchTool(max_num_results=3, vector_store_ids=[vector_store.id]),
    ],
)

result = Runner.run_sync(agent, "How to configure autoscaling in Kubernetes?")
print(result.final_output)
Enter fullscreen mode Exit fullscreen mode

Result

Technical Architecture of Docs AI Search

  • Embeddings via OpenAI: Documents are transformed into vector embeddings capturing rich semantic context.
  • Managed Vector Store: Efficient storage and retrieval of document embeddings, facilitating fast semantic search.
  • Agents SDK: Intelligent semantic search interactions to provide developers quick and contextually accurate answers.

Overall Architecture

Empathy in Engineering Docs AI Search

Empathy-driven engineering ensures Docs AI addresses genuine developer pain points:

  • Context-Aware Responses: Strictly rely on provided documentation to avoid misleading information.
  • Transparency: Clearly communicate the bounds of searchable data, enhancing developer trust.
  • Clear Communication of Limitations: Explicitly indicate when information is unavailable, enabling developers to take alternative actions confidently.

Maintaining Search Integrity

Effective maintenance of document repositories, including removing outdated or incorrect documentation, preserves the reliability of search outcomes:

client.vector_stores.files.delete(vector_store_id=vector_store.id, file_id=file_id)
Enter fullscreen mode Exit fullscreen mode

File deletion

After removal, searches transparently communicate the updated knowledge base status.

Potential Extensions for Enhanced Developer Experience

Future enhancements can include integration with real-time CI/CD logs, automatic documentation synchronization via APIs, and multi-modal embedding searches (combining text with visual content such as architecture diagrams).


For more tips and insights, follow me on Twitter @Siddhant_K_code and stay updated with the latest & detailed tech content like this.

AWS Q Developer image

Your AI Code Assistant

Implement features, document your code, or refactor your projects.
Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay