Implementation Notes
Practical notes on implementing AI-first documentation using tools like AnythingLLM, ingestion pipelines, and retrieval strategies.
Turning the AI-native documentation doctrine into reality involves selecting and configuring the right tools and workflows. Fortunately, the ecosystem for LLM-powered documentation assistants is growing rapidly. In this section, we’ll outline a high-level approach to implement an AI-first documentation system, and we’ll use AnythingLLM (an open-source framework) as a concrete example of how things can be set up. We’ll also mention other common components (like vector databases, LangChain, etc.) to stay platform-agnostic in principle.
1. Documentation as Code (Docs-as-code): Before diving into AI specifics, it’s worth emphasizing that treating documentation like code (in version control, with a clear structure and possibly CI/CD for publishing) greatly helps AI integration. When your docs are in Markdown files in a repository, it’s straightforward to feed them into AI pipelines. If your docs are only in PDF or wiki form, consider converting them to a text-friendly format. Many RAG systems have PDF loaders, but plain Markdown is easier to chunk and parse. If you have control over format, Markdown or reStructuredText or similar are ideal.
2. Ingestion Pipeline: This is the process of pulling in your documentation content and preparing it for the AI. A typical pipeline does the following:
- Read the docs (from files, or an API if using an external help center).
- Split the docs into chunks (often by paragraph or section). The splitting strategy can sometimes leverage the structure – e.g., each Markdown heading section becomes a chunk, or chunks are capped at, say, 200 tokens and split at sentence boundaries.
- Embed each chunk into a vector (using an embedding model) and store it in a vector database along with metadata (like the source document, section title, tags from frontmatter, etc.).
- Save references so that given a chunk result, we can link back to original doc (for citation or context).
Using AnythingLLM as an example: it provides a workflow where you create a “workspace” for your docs, then “upload” or point it at your documentation files. It will automatically convert them to text, chunk them into sections, embed those sections with a chosen embedding model, and store them (AnythingLLM can use various vector stores like FAISS or LanceDB). According to its docs, uploading just converts to text, and “moving to workspace” triggers chunking and embedding. Each chunk then lives in a vector index, ready to be retrieved by similarity to a query.
Crucially, AnythingLLM and similar tools preserve metadata. For instance, AnythingLLM attaches the original text to each vector, and it can store additional info like file name or headings. When a user asks something, the system will:
- Embed the user’s query.
- Do a similarity search in the vector DB to find the top relevant chunks.
- Optionally, filter or re-rank them (AnythingLLM has settings for an “Accuracy Optimized” search that searches more chunks and then filters).
- Take the top ~N chunks (say 5) above a relevance threshold and pass them to the LLM as context.
3. Choosing an LLM: The nice part of an AI-first doc system is you can be flexible with the language model. You could use OpenAI’s GPT-4 via API, or a local model like LLaMA2, etc. The docs remain the same; the only differences are in how well each model follows instructions and handles context length. If using a smaller model, you might need shorter context or more guidance. If using GPT-4, it can handle long docs but is costlier. The doctrine is agnostic to model – we assume the model can take a system message (instructions) and some content.
In AnythingLLM, for example, you can plug in different LLMs (open-source or API-based) and vector DBs as well. It’s a “full-stack” solution that wraps all these pieces behind a UI. For a more DIY approach, one could use LangChain or LlamaIndex in a Python app to achieve the same pipeline: they both have mechanisms to read docs, embed, store vectors, and query with an LLM chain.
4. System Prompt (Behavioral Metadata): We’ve discussed embedding some of this in documentation, but much will be configured as the system prompt for the model. With AnythingLLM, each workspace has a “Chat Settings > Prompt” where you define the rule set for that workspace. For example, if you’re documenting an API, your system prompt could say: “You are a documentation assistant for Product X. Answer questions using the documentation snippets provided. If information is not in the snippets, say you cannot find it. Respond in a friendly, technical tone. Include code examples if relevant,” etc. This is where you encode those guardrails and style preferences.
Some tools also allow dynamic injection of metadata into the prompt. For instance, they might replace a variable with the “intended-audience” from frontmatter if known, or include document titles. It’s good to know that anything you put in the system prompt eats into the token budget, so keep it concise. The combination of system prompt plus retrieved docs is usually what the model sees.
5. Retrieval Strategy: Not all queries are equal. Some might need one chunk (e.g., definition of a term), others might need multiple to synthesize (e.g., compare two related features). The retrieval step should ideally be tuned. By default, semantic similarity search does okay, but you might consider:
- Using keywords or metadata filtering. E.g., if the query contains “Redis”, filter to docs where product=Redis (if you have multiple products).
- Using multi-step retrieval: maybe first search for a broad topic, then within that for details. Tools like LlamaIndex offer query transformers that do this, or one can manually orchestrate with LangChain.
- Ensuring the AI knows the limits: e.g., AnythingLLM by default returns maybe top 4-6 chunks. If it’s not enough, it might not answer fully. There is a setting “Max Context Snippets” to adjust how many chunks to feed. If you have a large context window (like GPT-4 32k), you can feed more docs at once, but with smaller models you might have to be selective.
AnythingLLM’s “Accuracy Optimized” mode basically does a second pass (re-ranks more chunks) for better results at some cost. That is a nice feature to use when exactness is important.
6. Answer Composition and Guardrails: After retrieval, the model generates an answer. If you’ve set up the system prompt right, it should already avoid going off-script. Still, you may implement a post-processing:
- For instance, automatically append citation footnotes or links. If using a platform like GitHub Pages for docs, you could have the assistant provide a URL to the relevant doc page or anchor.
- If answer is below a certain confidence or uses words like “not sure”, maybe the system triggers a fallback (like, “This question might be better answered by a human, here’s a link to support”).
- Some solutions also do a quick check: feed the answer and original question back into an LLM asking “Does this answer use the provided info and is it correct?” – this is expensive and not foolproof, but it’s an extra layer some might choose for critical contexts.
7. Continual Doc Updates: Implementation-wise, how do we keep the AI updated when docs change? Ideally, integrate it with your docs CI. For example, every time you merge to main for your docs repository, you could run a job that re-ingests the docs into the vector store (or does a diff update if supported). Some systems allow incremental updates (only embedding changed files). AnythingLLM likely expects you to re-upload or sync manually for now, but one could automate it since it has an API or at least a process. The concept of documentation pipelines becomes important – treating the vector DB as just another output (like HTML site is an output, PDF manual is an output, so is the embeddings index).
8. Sandbox and Testing: Before rolling out to users, test internally. Have engineers and writers ask the AI a battery of questions (especially tricky ones) and see how it fares. Use those results to adjust either documentation content (maybe add an entry it missed) or tweak the retrieval settings. This internal testing is analogous to proofreading or user testing of documentation, but interactive.
9. Multi-platform support: Remember that the documentation prepared for AI can feed multiple assistants: ChatGPT plugins, internal Slack bots, voice assistants, etc. Being platform-agnostic means you prepare the docs and possibly even host the vector DB such that various interfaces can query it. For instance, you might use an internal API endpoint that given a query returns an answer with sources – Slack bot calls it, your website chatbot calls it, etc., all drawing from the same doc index.
10. User interface considerations: While not directly documentation, it’s worth mentioning: design the UI to set user expectations and gather feedback. For example, show a disclaimer “Answers are based on documentation v1.0 as of [date]” so they know it’s not the AI’s brain but actual docs. Provide a way to view more or full context (some chatbots let you expand the sources). Also, allow users to flag an answer as incorrect or unhelpful – this can pipe into your backlog for docs to improve.
Now, specifically about AnythingLLM: it’s an open-source project (MIT licensed) that provides a web UI and orchestrates much of this for you. It’s a great starting point if you want a self-hosted solution to chat with docs. You’d set it up, create a workspace (maybe one per product or version), and add your documentation files. It handles the splitting and storing. Then you can chat with it using an OpenAI model or even a local one. It also supports things like uploading whole GitHub repos, which is handy if your docs are in a repo (it will pull them). To learn more or get hands-on, one can refer to the AnythingLLM documentation and GitHub repo (for example, the docs at docs.useanything.com explain how to tune workspaces, manage settings like Temperature for creativity, etc.).
For those using cloud services, OpenAI offers features like “ChatGPT Retrieval Plugin” where you basically provide an index and it plugs into ChatGPT. Or platforms like Kapa.ai (mentioned earlier) which is more of a managed solution for companies (their demo was a Kubernetes doc bot). The principles remain the same: you need to supply structured docs, and the system does RAG.
Performance and Scalability: For large documentation sets (like thousands of pages), indexing can be heavy. Vector DB choice matters – FAISS is simple and works in-memory or file, Milvus or ElasticSearch vector might scale more. Ensure you choose one that fits your data size and query latency requirements. Also consider chunk size: too big = relevant info might be diluted, too small = need too many chunks to answer, possibly missing context. There’s a sweet spot often around a few sentences to a short paragraph (maybe 50-150 words) per chunk, but it varies.
Security and Access Control: If some docs are internal or restricted, an AI reading them should enforce that. This might mean separating indexes by audience or requiring auth to use certain indexes. Metadata can label sensitivity and you could integrate an access check. E.g., if an internal user asks something, it uses internal docs index; if external, it uses only public docs. So, when implementing, be mindful of what content goes in.
Monitoring: It’s wise to monitor usage. Log queries (anonymized) and what answers were given (and from which source docs). This not only helps improve docs but also ensures it’s not giving something wrong or inappropriate. If you see weird queries (like someone asking the bot for something out-of-scope), you might add that to a filter list.
In conclusion, implementing AI-first documentation is about marrying your documentation content with a retrieval and language model pipeline. By using tools like AnythingLLM or others, much of the heavy lifting is handled – but you still have to provide good docs and fine-tune the behavior. The good news is that all of this is achievable with open-source components and/or existing cloud services; one need not build a vector search or LLM from scratch. The focus for your team remains: maintain great docs, annotate them richly, and configure the AI interface to use them and only them effectively. This technology is rapidly evolving, so keep an eye on new features (like improved context handling, longer context windows, or adaptive retrieval techniques). However, the doctrine stands independent of any one tool: it’s about the mindset and structure of documentation. Now, to solidify these ideas, let’s look at some case studies applying the doctrine to real projects, and then we’ll summarize the doctrine with a checklist for easy reference.
How is this guide?
Last updated on