Commit b72701a
feat: Add search command with dual query formats (infix + MongoDB JSON) (#1098)
## Summary
This PR implements the complete search feature for Kernel Memory,
enabling users to query indexed content across multiple nodes and
indexes with advanced filtering and relevance scoring.
**Key Features:**
- ✅ Dual query formats: SQL-like infix notation and MongoDB JSON
- ✅ Multi-node parallel search with configurable weights
- ✅ Multi-index search with diminishing returns reranking
- ✅ Field-specific search with boolean operators (AND, OR, NOT)
- ✅ Relevance scoring (0.0-1.0) with weighted reranking
- ✅ Highlighting and snippet generation
- ✅ Query validation and security limits
- ✅ Comprehensive configuration and examples
**Components Added:**
- Core search service with node orchestration
- Dual query parsers (Infix + MongoDB JSON)
- SQLite FTS5 integration with stemming
- Weighted diminishing returns reranking algorithm
- CLI search command with 13 configuration flags
- Consumer-friendly documentation (CONFIGURATION.md)
- Interactive examples command (`km examples`)
**Architecture:**
- Transport-agnostic search service (ready for Web/RPC)
- Parallel node searching with timeout handling
- Memory-safe result limiting with recency bias
- Comprehensive error handling and validation
## Test Coverage
- 429 unit tests for reranking algorithm (all 5 examples from
requirements)
- 324+ tests for MongoDB JSON parser
- 345+ tests for Infix parser
- 206 equivalence tests (both parsers return identical AST)
- 459 tests for LINQ query builder
- Integration tests for search service
- All search scenarios from requirements covered
## Documentation
- **CONFIGURATION.md** (768 lines) - Complete consumer guide
- Covers nodes, search settings, FTS indexes
- 4 practical configuration examples
- Impact warnings for configuration changes
- Focused on implemented features only
- **Examples Command** (`km examples`) - Interactive help
- Practical examples for students, parents, professionals
- All CLI commands covered (put, search, list, get, delete, nodes,
config)
- Power user tips for advanced scenarios
## Test Plan
- [x] Simple keyword search: `km search "doctor appointment"`
- [x] Field-specific search: `km search "title:lecture AND tags:exam"`
- [x] Boolean logic: `km search "content:insurance AND (tags:health OR
tags:auto)"`
- [x] MongoDB JSON: `km search '{"content": "test", "tags":
"important"}'`
- [x] Multi-node search with weights
- [x] Highlighting and snippets
- [x] Pagination (limit/offset)
- [x] Quality filtering (min-relevance)
- [x] Query validation
- [x] Configuration loading and validation
- [x] Examples command display
- [x] All builds pass with zero warnings
## Breaking Changes
None - This is a new feature addition.
## Implementation Notes
**Follows Requirements:**
- All 5 score calculation examples verified with tests
- Security limits implemented (query depth, operator count, field value
length, parse timeout)
- NoSQL-like semantics for flexible metadata
**Success Criteria Met:**
1. ✅ Users can search with simple queries
2. ✅ Boolean logic works
3. ✅ Both infix and JSON formats supported
4. ✅ Multi-index search with reranking
5. ✅ Relevance scores 0.0-1.0
6. ✅ All tests passing
7. ✅ Zero-tolerance build passes (0 warnings, 0 errors)
8. ✅ Documentation complete
---------
Co-authored-by: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>1 parent c376e9a commit b72701a
File tree
107 files changed
+9969
-130
lines changed- src
- Core
- Config
- SearchIndex
- Search
- Exceptions
- Models
- Query
- Ast
- Parsers
- Reranking
- Storage
- Main
- CLI
- Commands
- Services
- tests
- Core.Tests
- Config
- Search
- Models
- Query
- Reranking
- Storage
- Models
- Main.Tests
- Integration
- Unit
- CLI
- Commands
- Models
- OutputFormatters
- Services
- Settings
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
107 files changed
+9969
-130
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
0 commit comments