Skip to content

feat: compact search default + brain_expand tool + entity dedup#60

Merged
EtanHey merged 2 commits intomainfrom
fix/smart-search-entity-dedup
Feb 27, 2026
Merged

feat: compact search default + brain_expand tool + entity dedup#60
EtanHey merged 2 commits intomainfrom
fix/smart-search-entity-dedup

Conversation

@EtanHey
Copy link
Copy Markdown
Owner

@EtanHey EtanHey commented Feb 27, 2026

Summary

  • Compact search by default: brain_search now returns 150-char snippets + chunk_id pointers instead of full content (~60% token savings). Use detail="full" for verbose output.
  • New brain_expand tool: First-class MCP tool to drill into specific search results — takes chunk_id and returns full content + surrounding context.
  • Entity dedup in digest: _dedup_entities() deduplicates by (normalized_name, entity_type) before resolution — fixes duplicate entity references when content mentions the same entity multiple times.
  • Vector similarity fallback: resolve_entity() now accepts optional embed_fn for cosine similarity matching (threshold 0.92 auto-match, 0.75 fuzzy match) when exact/alias/FTS fails.

Changes

File Change
mcp/__init__.py Register brain_expand tool (8 tools now), rename formatdetail param, update server instructions
mcp/_shared.py _build_compact_result() returns snippet (150 chars) + chunk_id instead of content (500 chars)
mcp/search_handler.py Default detail="compact", backward compat for old format kwarg
pipeline/batch_extraction.py New _dedup_entities() function, dedup before resolution
pipeline/digest.py Response uses deduped entity list
pipeline/entity_resolution.py resolve_entity() accepts embed_fn, vector similarity cascade (0.92/0.75 thresholds)

Test plan

  • 17 new tests in tests/test_smart_search_entity_dedup.py
  • Updated test_phase6_critical.py and test_search_routing.py for new compact format
  • 642 tests pass, 0 failures

🤖 Generated with Claude Code

Make brain_search return compact results by default (150-char snippets + chunk_id
for drill-down), add brain_expand as a first-class MCP tool, deduplicate entity
mentions in digest pipeline, and add vector similarity fallback to entity resolution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 27, 2026

Warning

Rate limit exceeded

@EtanHey has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 42 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 26e4c5f and 2a66178.

📒 Files selected for processing (10)
  • src/brainlayer/mcp/__init__.py
  • src/brainlayer/mcp/_shared.py
  • src/brainlayer/mcp/search_handler.py
  • src/brainlayer/pipeline/batch_extraction.py
  • src/brainlayer/pipeline/digest.py
  • src/brainlayer/pipeline/entity_resolution.py
  • tests/test_phase6_critical.py
  • tests/test_search_routing.py
  • tests/test_smart_search_entity_dedup.py
  • tests/test_think_recall_integration.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/smart-search-entity-dedup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@EtanHey EtanHey merged commit 0aa2a95 into main Feb 27, 2026
5 checks passed
@EtanHey EtanHey deleted the fix/smart-search-entity-dedup branch February 27, 2026 21:40
EtanHey added a commit that referenced this pull request Feb 28, 2026
PR #60 added entity dedup for future digests, but existing duplicate
entities in the DB were never cleaned up. This script finds duplicates
by (lower(name), entity_type), keeps the entity with the most relations
and evidence chunks, and merges orphans using merge_entities().

Results on brainlayer.db: 39→37 entities, 2 case-variant duplicates
resolved (BrainLayer/brainlayer, Golems/golems). zikaron.db was clean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@EtanHey EtanHey mentioned this pull request Feb 28, 2026
4 tasks
EtanHey added a commit that referenced this pull request Feb 28, 2026
PR #60 added entity dedup for future digests, but existing duplicate
entities in the DB were never cleaned up. This script finds duplicates
by (lower(name), entity_type), keeps the entity with the most relations
and evidence chunks, and merges orphans using merge_entities().

Results on brainlayer.db: 39→37 entities, 2 case-variant duplicates
resolved (BrainLayer/brainlayer, Golems/golems). zikaron.db was clean.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
EtanHey pushed a commit that referenced this pull request May 2, 2026
- Recent Hardening section traces each claim to a merged PR
- BrainBar build-script guards (#264, #265) called out at the install step
- Phase B preventive infra block (orchestrator#58, #60) connects deploy registry
  to the BrainBar build-stamp + canonical-build refuse layer
- In-flight PR #251 entry documents NSPanel revival + trigram FTS5 startup-safety
  guard (10K-chunk threshold) + preserved /tmp/brainbar.sock pub/sub plane

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
EtanHey pushed a commit that referenced this pull request May 3, 2026
- Recent Hardening section traces each claim to a merged PR
- BrainBar build-script guards (#264, #265) called out at the install step
- Phase B preventive infra block (orchestrator#58, #60) connects deploy registry
  to the BrainBar build-stamp + canonical-build refuse layer
- In-flight PR #251 entry documents NSPanel revival + trigram FTS5 startup-safety
  guard (10K-chunk threshold) + preserved /tmp/brainbar.sock pub/sub plane

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
EtanHey added a commit that referenced this pull request May 3, 2026
…267)

- Recent Hardening section traces each claim to a merged PR
- BrainBar build-script guards (#264, #265) called out at the install step
- Phase B preventive infra block (orchestrator#58, #60) connects deploy registry
  to the BrainBar build-stamp + canonical-build refuse layer
- In-flight PR #251 entry documents NSPanel revival + trigram FTS5 startup-safety
  guard (10K-chunk threshold) + preserved /tmp/brainbar.sock pub/sub plane

Co-authored-by: Test User <test@example.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant