# How to Use Knowledge Bases

### Standalone Knowledge Base

The standalone Knowledge Base Node is best used when the agent is always expected to consult the knowledge base (e.g. source of truth documents, compliance policies, etc).

<figure><img src="/files/gdp45weqrS902Jj3GIZS" alt=""><figcaption></figcaption></figure>

The standalone Knowledge Base Node requires an input, such as the user's question. This input serves as the query that the Knowledge Base uses to fetch relevant context. If there are multiple inputs connected, you can specify which one to use in the Knowledge Base settings.

{% hint style="warning" %}
**If no input is connected or specified in the Knowledge Base Node, it will not return a result.**
{% endhint %}

<figure><img src="/files/LVwA7MX4O34Fbdd22YIH" alt=""><figcaption><p>Configure Input Query in the settings</p></figcaption></figure>

### Search Knowledge Base Tool

Large Language Models (LLMs) can use the Search Knowledge Base Tool to intelligently query your documents during a live conversation. Rather than a static lookup, the LLM dynamically generates search queries to retrieve relevant information based on the context of the discussion.

When you select a knowledge base inside the LLM, the "Search Knowledge Base Tool" will be automatically added. You can reference this tool and prompt the LLM on when and how to search the knowledge base.&#x20;

<figure><img src="/files/7ZYjBLPoVbfXYimWqud4" alt=""><figcaption><p>Add the knowledge base as a tool to the LLM</p></figcaption></figure>

### Search Parameters

Both Knowledge Base Node and Search Knowledge Base Tool have a set of search parameters to refine the search results.

![Search Parameters in the standalone node](/files/JRiIP5h0N69ROu6L9D2Z)

<figure><img src="/files/ggudZtt9366sm14pIQpw" alt=""><figcaption><p>Search Parameters in the tool</p></figcaption></figure>

* **Output Format:** Choose between chunks, pages, and docs. This is not the output the end user will see but the unit of information to be retrieved. For example, if "docs" is selected, the entire document will be retrieved. By default, "chunks" is selected and should suit most use cases.
* **Metadata Filter Strategy:** Choose between Strict Filter, Loose Filter, and No Filter. See below section for more details.
* **Query Strategy:** Choose between Semantic, Keyword, and Hybrid. See below section for more details.
* **Top Results:** Number of search results ranked by relevance.
* **Max Characters:** Limits the number of characters sent to the LLM.
* **Answer Multiple Questions:** Get the answers from multiple questions in parallel.
* **Advanced Q\&A:** Handle questions to compare or summarize documents. By enabling this feature, the knowledge base search will automatically use "retrieval utilities" to select the best mechanism to answer the user questions depending on whether the question aims to: retrieve a fact, compare a set of documents, or summarize a document inside the knowledge base.
* **Rerank:** Get more precise information retrieval. The knowledge base will divide its number of results in half with the most relevant results, using a sophisticated ranking algorithm. This will reduce token usage.
* **Query Transformation:** Get more precise information retrieval. Forces the knowledge base to rewrite the user message as a better question. This increases the quality of the search results for the language model.

### Metadata Filter Strategy

**Metadata filtering** helps narrow down the documents retrieved from a vector store. The filters operate on metadata associated with each document, such as date, source, topic, etc. StackAI imports tags and metadata fields from your connections, and you can add custom metadata as well.

<div align="left"><img src="/files/Ng8M4vOUKxWVtv6XT5Jp" alt="Example of file metadata" width="563"></div>

If you want to surface as much information as possible, it is best to use **no filter**. In this case, no metadata constraints are applied. This strategy is best to use when you don't have a very large knowledge base.

With **loose filtering**, metadata is used as a soft constraint. The system prefers documents matching the filter, but still considers other documents. This gives you the best of both worlds and is best used when metadata is helpful but not critical.

**Strict filtering** should be used for situations where you have many similar documents in your KB that you need to distinguish between. With a strict filter, metadata constraints are hard requirements. Only documents matching the specified metadata are eligible for retrieval.

### Query Strategy

In Retrieval-Augmented Generation (RAG), **keyword-based search** relies on traditional information retrieval techniques that match exact or fuzzy terms within documents. This approach works best when the query and content use consistent vocabulary, such as in legal, technical, or structured domains where terminology is predictable. It's especially useful when you know the precise terms you're looking for.

**Semantic querying**, on the other hand, uses vector embeddings to represent the meaning of both queries and documents. It enables retrieval based on conceptual similarity, rather than exact keyword matches. This makes it well-suited for natural language questions, varied phrasing, and content where language is less standardized—such as customer support, internal knowledge bases, or conversational search. By focusing on meaning, semantic search improves recall, but may miss documents with exact keyword relevance.

**Hybrid querying** combines both strategies—typically by blending keyword and semantic relevance scores or performing multi-stage retrieval. This approach provides the benefits of both precision and flexibility, making it ideal for general-purpose RAG systems that must handle a variety of user intents and content types. While slightly more complex to implement, hybrid search often yields the most balanced and robust retrieval performance in production applications.

### Citation

Citation is controlled by the Large Language Model node, regardless of using the knowledge base node or tool.

<div align="left"><figure><img src="/files/1Ne2oz2UrllNXsvK5rf2" alt="" width="563"><figcaption></figcaption></figure></div>

When enabled, citations are displayed as superscripts in the interface. Users can click on the references to review the specific information within the source files.

<figure><img src="/files/8Mzj9u9oatWBj2XnEhzG" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stackai.com/workflow-builder/core-nodes/knowledge-bases/how-to-use-knowledge-bases.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
