LearnNewsExamplesServices
Frontmatter
titlefix #7467: AI query blog filtering issue
authorharikrishna-au
stateMerged
createdAtOct 13, 2025, 3:54 AM
updatedAtOct 14, 2025, 1:41 PM
closedAtOct 13, 2025, 10:39 AM
mergedAtOct 13, 2025, 10:39 AM
branchesdevdev
urlhttps://github.com/neomjs/neo/pull/7472
Merged
harikrishna-au
harikrishna-au commented on Oct 13, 2025, 3:54 AM

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

The PR fulfills these requirements:

  • It's submitted to the dev branch, not the main branch
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

Description:

This PR fixes issue #7467 where the AI query system was unable to find content in blog posts when using the -t blog filter.

Problem: The npm run ai:query -- -q "term" -t blog command was failing to return results even when the search term existed in blog files. This was breaking the AI knowledge base's ability to access blog content, undermining the framework's "Anti-Hallucination Policy".

Root Cause:

  • Blog content is stored in the knowledge base as type: 'guide' with isBlog: true
  • The query filter was incorrectly looking for type: 'blog' (which doesn't exist)
  • This mismatch caused zero results for all blog queries

Solution: Updated the filtering logic in buildScripts/ai/queryKnowledgeBase.mjs to correctly handle blog queries:

// Before (broken)
whereClause = {type: type};

// After (fixed)
if (type === 'blog') {
    whereClause = {
        type: 'guide',
        isBlog: 'true'  // ChromaDB stores metadata as strings
    };
} else {
    whereClause = {type: type};
}


</div>
                </div>
            </div>
            <div id="timeline-7472-1" class="neo-timeline-item comment" data-record-id="timeline-7472-1">
                <div id="timeline-7472-1-target" class="neo-timeline-avatar">
                    <img src="https://github.com/tobiu.png?size=40" alt="tobiu" loading="lazy">
                </div>
                <div class="neo-timeline-content">
                    <div class="neo-timeline-header">
                        <a class="neo-timeline-user" href="https://github.com/tobiu" target="_blank">tobiu</a>
                        <span class="neo-timeline-date">commented on Oct 13, 2025, 10:39 AM</span>
                    </div>
                    <div class="neo-timeline-body">

<p>Thank you for correctly identifying the problem! More details from Gemini:</p>
<blockquote>
<p>  ✦ Hi @harikrishna-au, thank you for your contribution and for fixing this bug!</p>
<p>  Your analysis was spot-on. You correctly identified that the query was failing because it was looking for <code>type:    &#39;blog&#39;</code> while the data was stored as <code>{type: &#39;guide&#39;, isBlog: &#39;true&#39;}</code>.</p>
<p>  We are approving and merging this PR because it provides an effective and immediate fix to the problem.</p>
<p>  From an architectural standpoint, this solution is a <strong>workaround</strong>. The change in <code>queryKnowledgeBase.mjs</code> patches the
  issue on the &quot;reading&quot; side, but the root cause is on the &quot;writing&quot; side in <code>createKnowledgeBase.mjs</code>. The
  long-term, more robust solution is to fix the data at its source by assigning <code>type: &#39;blog&#39;</code> during the initial
  indexing.</p>
<p>  We will handle this refactoring in a follow-up task. Your work was crucial in highlighting this discrepancy and
  getting the feature working again.</p>
<p>  Great job, and we hope to see more contributions from you in the future.</p>
</blockquote>
<hr>


</div>
                </div>
            </div>
            <div id="timeline-7472-2" class="neo-timeline-item comment" data-record-id="timeline-7472-2">
                <div id="timeline-7472-2-target" class="neo-timeline-avatar">
                    <img src="https://github.com/tobiu.png?size=40" alt="tobiu" loading="lazy">
                </div>
                <div class="neo-timeline-content">
                    <div class="neo-timeline-header">
                        <a class="neo-timeline-user" href="https://github.com/tobiu" target="_blank">tobiu</a>
                        <span class="neo-timeline-date">commented on Oct 14, 2025, 12:50 PM</span>
                    </div>
                    <div class="neo-timeline-body">

<p>Test comment from the MCP server.</p>
<hr>


</div>
                </div>
            </div></div>