Skip to content

Conversation

@DonaldoDes
Copy link

Summary

This PR adds comprehensive Dataview query support to Basic Memory, enabling Obsidian-style queries in markdown notes with automatic relation tracking and MCP tool integration.

Features

Core Dataview Engine

  • Query Parser: Full lexer/parser for Dataview query syntax (LIST, TABLE, TASK, CALENDAR)
  • Expression Evaluator: Support for filters, sorting, grouping, and field expressions
  • Result Formatter: Multiple output formats (markdown tables, lists, task lists)

MCP Integration

  • read_note: Execute Dataview queries when reading notes
  • build_context: Include Dataview results in context building
  • Notes Provider: Access to full note content for query execution

Automatic Relation Tracking

  • Dataview Detector: Identify queries in markdown content
  • Refresh Manager: Auto-refresh relations when notes change (with debouncing)
  • Persistence: Store discovered links as relations in the database

Additional Tools

  • force_reindex: MCP tool to rebuild search index on demand

Testing

  • 19 detector tests ✅
  • 315+ total Dataview tests
  • Integration tests for MCP tools
  • E2E tests for relation persistence

Commits

  1. fix: handle datetime strings from SQLite raw SQL queries
  2. feat: Add Dataview query parser and executor with MCP integration
  3. feat(mcp): add force_reindex tool to rebuild search index
  4. chore: add crush config and test files
  5. feat(dataview): persist discovered links as relations
  6. fix(dataview): filter non-string targets in refresh_dataview_relations
  7. feat(dataview): automatic refresh of Dataview relations with debouncing
  8. fix(dataview): provide notes_provider to build_context for Dataview queries
  9. feat(dataview): provide notes to MCP tools for query execution
  10. test(dataview): add tests for MCP tools dataview integration

Documentation

  • DATAVIEW_QUICKSTART.md: Getting started guide
  • DATAVIEW_IMPLEMENTATION_SUMMARY.md: Technical overview
  • DATAVIEW_TEST_REPORT.md: Test coverage report
  • src/basic_memory/dataview/README.md: API documentation
  • src/basic_memory/dataview/INTEGRATION.md: Integration guide

Breaking Changes

None. This is a purely additive feature.

Related Issues

Closes #[issue-number] (if applicable)

DonaldoDes and others added 10 commits January 29, 2026 10:28
SQLite raw SQL queries return datetime columns as strings rather than
datetime objects. Added parse_datetime helper to handle both formats
and ensure timezone-awareness in context service results.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Donaldo <donaldo.desousa@icloud.com>
- Implement Lexer, Parser, AST for Dataview queries
- Support TASK, LIST, TABLE query types
- Support FROM, WHERE, SORT, LIMIT clauses
- Implement Executor with SQLite integration
- Add field resolver, expression evaluator, task extractor
- Integrate with MCP tools (read_note, search_notes, build_context)
- Add 248 tests with 100% pass rate
- Add comprehensive documentation

Query types supported:
- LIST: List notes from folders/tags
- TABLE: Display notes in table format
- TASK: Extract tasks from markdown

Features:
- FROM clause: folder, tag, AND/OR combinations
- WHERE clause: comparisons, logical operators, functions
- SORT clause: single/multiple fields, ASC/DESC
- LIMIT clause: result limiting
- Link extraction: automatic wikilink discovery
- Error handling: graceful failures with detailed messages

Performance:
- < 1ms per query (tested with real vault)
- 40% code coverage across entire codebase
- 248/248 tests passing

Integration:
- read_note: enable_dataview=True (default)
- search_notes: enable_dataview=False (default)
- build_context: enable_dataview=True (default)

Fixes:
- Lexer: Support boolean literals (true/false/null)
- Lexer: Support tag syntax (#tag)
- Executor: Handle None values in sorting
- Expression evaluator: Proper error messages for unknown functions
- Tests: Correct line tracking expectations
Adds a new MCP tool that allows users to force a full reindex of the
search index without modifying or deleting any notes. Useful when:
- Search returns empty results for content that exists
- Search index appears stale or out of sync
- After recovering from database issues

The tool calls the existing /search/reindex API endpoint and provides
clear feedback about the operation status.
- Fix _filter_by_from() to support nested file structure
- Fix file_content desync after frontmatter update
- Add refresh_dataview_relations() for auto-update
- Add dataview_link relation type
- Add comprehensive E2E and integration tests

Closes US-001, US-002
Skip datetime.date and other non-string objects returned by Dataview queries
when resolving links to create dataview_link relations.

Prevents TypeError when processing Milestone.due_date fields that return
date objects instead of strings.
- Add DataviewRefreshManager for automatic refresh
- Debounce 5s to batch rapid changes
- Only refresh entities impacted by changes (based on FROM clauses)
- Cache entities with Dataview queries for performance
- Integrate into SyncService.sync_markdown_file()

No more manual refresh needed - relations update automatically.
…ueries

- Add GET /entities/dataview endpoint to knowledge_router
- Add list_entities_for_dataview method to KnowledgeClient
- Pass notes_provider to create_dataview_integration in build_context
- Add TDD tests for build_context Dataview integration

Fixes: Dataview queries in build_context were returning 0 results because
no notes_provider was passed to the DataviewIntegration.
- Pass notes_provider to create_dataview_integration() in read_note
- Include result_markdown in build_context output instead of summary
- Add file.path to query results for proper link resolution
- Support nested file structure in FieldResolver with fallback
- Read entity content from disk in dataview_refresh_manager
- Call force_refresh_all() after sync to update dataview relations

Closes US-003
- Add test_read_note_dataview.py (4 tests)
- Add test_build_context_dataview.py (8 tests)
- Fix test_dataview_relations_persistence assertions
@CLAassistant
Copy link

CLAassistant commented Jan 29, 2026

CLA assistant check
All committers have signed the CLA.

@phernandez
Copy link
Member

Hi thanks @DonaldoDes for the PR. It looks pretty cool. I will check it out.

Can you tell me more about how you've been using BM with the Dataview info from Obsidian? I haven't had a chance to explore that yet. You can also dm me on our discord or email me at paul@basicmemory.com.

There are couple issues with the files in your PR that we' d need to address

  • some extra stuff like the "crush" has your hardcoded paths
  • tests have lots of print statements

We can clean this up as needed.

Also, would you mind signing off on your commits? This helps us to ensure we have all the copyright stuff ironed out correctly.

To sign off

git commit -s -m "your message"

Your AI can also sign off existing commits and do a force push.

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.

3 participants