1. Using the Knowledge Library

Using the Knowledge Library

How to organize Knowledge Library articles and get the best search results for an AI agent, using AI enrichment, reranking and summarization.

Overview

The Knowledge Library stores unstructured information, such as text, PDFs and Word documents, for an AI agent to search. An agent searches it with the Search Knowledge Library task, which returns the snippets that best match a query.

Good results depend on two things: how the articles are organized, and how the search is set up.

Organizing your articles

Sort articles into rooms and shelves. Rooms are broad areas, such as a department or product, and shelves are the topics within a room.

Searches can then be limited to the rooms or shelves that are relevant, which keeps unrelated content out of the results:

loading...

You can also filter by specific articles (filter.by_article) or drop weak matches with a minimum score (filter.by_score).

Getting better search results

Passing the user's message straight into the search works, but often misses the best snippets. User messages tend to be short, vague, or depend on earlier parts of the conversation.

For better results, combine these steps in one search:

  1. Enrich the query with query.text_small.ai_enrich, so it matches your articles more closely.
  2. Return more snippets by setting return.limit higher, typically 8 to 16.
  3. Rerank with return.rerank to put the most relevant snippets first, and keep only the best few with rerank.limit, typically 4 to 8.
  4. Summarize the snippets with return.ai_summarize into a short answer.
  5. Pass the answer to the conversational AI agent, which replies to the user.
loading...

The sections below explain each option.

Enriching the query

ai_enrich uses an LLM to rewrite the query before searching, so it matches the wording in your articles more closely. There are two common approaches:

  • Add context and keywords. Ask the LLM to expand the question with keywords or details from the conversation. This helps most when the question is vague or ambiguous.
  • Write an example answer. Ask the LLM to write an example of the article you expect to find, eg. a short piece of documentation explaining the feature the user asked about. The example often matches the real article better than the question does.

Reranking the results

The search returns snippets in order of vector similarity, which doesn't always reflect how useful they are. rerank reorders them by relevance to a query, so the best snippets come first.

Set rerank.query_with to choose what to rank against:

  • text_small (default) - the original query, usually the user's message
  • ai_enrich - the enriched query

Ranking against the original question works well after enrichment, because it checks the results against what the user actually asked.

Summarizing the results

ai_summarize uses an LLM to turn the snippets into a short answer, outside the main conversation. This keeps the conversation focused and uses fewer tokens.

Include the user's question, and any useful context, in ai_summarize.system_prompt so the summary answers the right question.

WARNING

Summarizing can lose details or context from the snippets. If the agent needs exact wording, such as prices or policy text, pass the snippets to the agent instead.

Testing your searches

Set return.debug to true and use the Search Knowledge Library Debug block to see the enriched query, the matched snippets and their scores. Try different prompts, limits and filters until the right snippets come back.