{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"redocly_category":"Products","product_name":"AI Agent Foundry","type":"markdown"},"seo":{"title":"Querying a Knowledge Base","description":"Treasure Data Product Documentation · Collect and Unify · Segment and Activate · Experiment and Analyze · Decisioning Automate with AI Scale and Trust.","siteUrl":"https://docs.treasuredata.com","lang":"en-US","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"querying-a-knowledge-base","__idx":0},"children":["Querying a Knowledge Base"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["After you create a knowledge base for your AI project, you'll want to do some quick queries to ensure you have the expected data."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"query-simulation","__idx":1},"children":["Query Simulation"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This topic includes:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/ai-agent-foundry/knowledgebase/querying-a-knowledge-base#list-columns-simulation-examples"},"children":["List Columns Simulation Examples"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/ai-agent-foundry/knowledgebase/querying-a-knowledge-base#search-schema-simulation-examples"},"children":["Search Schema Simulation Examples"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/ai-agent-foundry/knowledgebase/querying-a-knowledge-base#query-data-directly-simulation-examples"},"children":["Query Data Directly Simulation Examples"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can check the setup of your Knowledge Bases by selecting the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Details"]}," tab"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/knowledge-base-details.be1fce016409455ffc3f131bbd59a7d5cdd05aeb31b3e8d1818833d57d059bcf.91c26685.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To simulate a Knowledge Base, select the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Test"]}," tab."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/knowledge-base-test-tab.cbf883cee5ed1d5ff9f75d29497aa9c51cf56ec31981646440cc40d470a8b8e2.91c26685.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"list-columns-simulation-examples","__idx":2},"children":["List Columns Simulation Examples"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["List Columns"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Enter table names"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/knowledge-base-list-columns.3813686296fca15161765ff28c170a76565b4443c27ce62e0684653d44d9e220.91c26685.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"search-schema-simulation-examples","__idx":3},"children":["Search Schema Simulation Examples"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Enter keywords to search"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/knowledge-base-search-schema.14fb0c19c2af235561532a9f98b884d5183eaa218e363f73c08d63d1dfc69073.91c26685.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"query-data-directly-simulation-examples","__idx":4},"children":["Query Data Directly Simulation Examples"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Enter a SQL statement to run"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/knowledge-base-query-data.949ac83a5176da23e5f6815daeef12dd040cd9eb72880be49aeacded115dbbd0.91c26685.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"understanding-query-result-formats","__idx":5},"children":["Understanding Query Result Formats"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Database knowledge bases support two result formats: ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Markdown-KV"]}," and ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["JSON"]},". The format you selected when creating the knowledge base determines how query results are displayed in the Test tab."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"markdown-kv-format","__idx":6},"children":["Markdown-KV Format"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When you select ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Markdown-KV"]}," as the Format Type, query results are returned in a structured, human-readable format with headings and key-value pairs."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["List Columns example:"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/knowledge-base-markdown-kv-list-columns.7bbfd81bd2cf34e5f04c824e7e20d15824363dec5374ef765c9db38057db3cd4.91c26685.png","alt":"List Columns result in Markdown-KV format"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The result shows database and table information with column details in a structured format:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"markdown","header":{"controls":{"copy":{}}},"source":"# Database \"retail_demo\"\n## Table \"customer_profiles\"\n### Column 1\nname: customer_id\ntype: varchar\ncomment:\n### Column 2\nname: first_name\ntype: varchar\ncomment:\n","lang":"markdown"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Query data directly example:"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/knowledge-base-markdown-kv-query-result.95cbbf9b4aead7c2b715eb070660805e584a79c30e656d34c71d933a93a1a313.91c26685.png","alt":"Query result in Markdown-KV format"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example, running this query:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sql","header":{"controls":{"copy":{}}},"source":"SELECT customer_id, first_name, last_name, city, state \nFROM customer_profiles \nLIMIT 1\n","lang":"sql"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Returns results in this format:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"markdown","header":{"controls":{"copy":{}}},"source":"# Records\n## Record 1\ncustomer_id: CUST-00613\nfirst_name: Aiden\nlast_name: Hernandez\ncity: San Diego\nstate: CA\n","lang":"markdown"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Truncation warning:"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When query results exceed the Max rows limit, a warning message is automatically appended to help the AI agent recognize that results are incomplete:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/knowledge-base-markdown-kv-truncation-warning.df1c07dd7980ba9dd60c59de4a87b6877c87a4bf5410e602d2fc65da2f8029e4.91c26685.png","alt":"Truncation warning in Markdown-KV format"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example, when Max rows is set to 2 but the query attempts to retrieve more records, the following warning appears:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"markdown","header":{"controls":{"copy":{}}},"source":"# Warning\n[TRUNCATED] Results limited to 2 rows. To retrieve more data, add pagination \nto your SQL query using OFFSET N LIMIT M (OFFSET must come before LIMIT), \nor add WHERE conditions to narrow the results.\n","lang":"markdown"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This warning prompts the AI agent to refine the query with pagination or additional filtering conditions."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"json-format","__idx":7},"children":["JSON Format"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When you select ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["JSON"]}," as the Format Type, query results are returned in traditional JSON format, similar to previous versions of the knowledge base feature."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"key-differences","__idx":8},"children":["Key Differences"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Feature"},"children":["Feature"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Markdown-KV"},"children":["Markdown-KV"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"JSON"},"children":["JSON"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Result readability"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["High - structured headings with key-value pairs"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Moderate - standard JSON arrays"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Truncation awareness"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Agent receives explicit warning when results are cut off"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["No explicit warning"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Table filtering"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Not available - all database tables included"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Available via Table configuration"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Max rows / Timeout settings"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Fully supported"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Limited or ignored"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Next Step"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/ai-agent-foundry/ai-agent/creating-an-agent"},"children":["Creating an Agent"]}]}]},"headings":[{"value":"Querying a Knowledge Base","id":"querying-a-knowledge-base","depth":1},{"value":"Query Simulation","id":"query-simulation","depth":2},{"value":"List Columns Simulation Examples","id":"list-columns-simulation-examples","depth":3},{"value":"Search Schema Simulation Examples","id":"search-schema-simulation-examples","depth":3},{"value":"Query Data Directly Simulation Examples","id":"query-data-directly-simulation-examples","depth":3},{"value":"Understanding Query Result Formats","id":"understanding-query-result-formats","depth":2},{"value":"Markdown-KV Format","id":"markdown-kv-format","depth":3},{"value":"JSON Format","id":"json-format","depth":3},{"value":"Key Differences","id":"key-differences","depth":3}],"frontmatter":{"seo":{"title":"Querying a Knowledge Base"}},"lastModified":"2026-04-14T03:45:36.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/products/customer-data-platform/ai-agent-foundry/knowledgebase/querying-a-knowledge-base","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}