Skip to content

Reorganize the code to make it crystal clear how the same logic is implemented in Doublets and Neo4j#14

Merged
konard merged 6 commits intomainfrom
issue-13-0b67341a17ae
Dec 31, 2025
Merged

Reorganize the code to make it crystal clear how the same logic is implemented in Doublets and Neo4j#14
konard merged 6 commits intomainfrom
issue-13-0b67341a17ae

Conversation

@konard
Copy link
Member

@konard konard commented Dec 29, 2025

Summary

This PR addresses issue #13 by reorganizing the codebase to make it crystal clear how the same logic is implemented in both Doublets and Neo4j databases.

Complete Separation of Neo4j and Doublets Code

All source files are now split into separate directories/files for easy comparison. No file contains mixed Neo4j and Doublets logic.

Benchmark Files

Directory Purpose
rust/benches/benchmarks/neo4j/ All Neo4j benchmarks using Cypher queries
rust/benches/benchmarks/doublets/ All Doublets benchmarks using direct memory access

Library Source Files

File Purpose
rust/src/benched/neo4j_benched.rs Neo4j Benched trait implementations
rust/src/benched/doublets_benched.rs Doublets Benched trait implementations
rust/src/neo4j_impl.rs Documents how Neo4j implements the common interface
rust/src/doublets_impl.rs Documents how Doublets implements the common interface
rust/src/client.rs Neo4j HTTP client (pure Neo4j code)
rust/src/transaction.rs Neo4j transaction wrapper (pure Neo4j code)

Is This Real Separation or Duplicated Code?

Yes, the benchmarks use the separate implementations!

Each benchmark file in neo4j/ or doublets/ creates and uses the appropriate storage backend:

  • Neo4j benchmarks (e.g., neo4j/create.rs) instantiate Exclusive<Client<usize>> which uses HTTP API calls to Neo4j
  • Doublets benchmarks (e.g., doublets/create.rs) instantiate unit::Store or split::Store which uses direct memory access

The same benchmark logic (create, update, delete, each) runs against completely different storage backends, allowing fair performance comparison.

Benchmark File Structure

Each benchmark directory has the same structure for easy side-by-side comparison:

benchmarks/neo4j/          benchmarks/doublets/
├── mod.rs                 ├── mod.rs
├── create.rs              ├── create.rs
├── update.rs              ├── update.rs
├── delete.rs              ├── delete.rs
└── each/                  └── each/
    ├── mod.rs                 ├── mod.rs
    ├── all.rs                 ├── all.rs
    ├── identity.rs            ├── identity.rs
    ├── concrete.rs            ├── concrete.rs
    ├── outgoing.rs            ├── outgoing.rs
    └── incoming.rs            └── incoming.rs

The Common Interface

Both databases implement the Doublets<T> trait from the doublets crate:

Operation Method Description
Create create_point() Insert a point link (id = source = target)
Update update(id, src, tgt) Modify source and target of existing link
Delete delete(id) Remove a link by its ID
Each All each(handler) Iterate all links matching [*, *, *]
Each Identity each_by([id,*,*], h) Find links by ID constraint
Each Concrete each_by([*,s,t], h) Find links by source AND target
Each Outgoing each_by([*,s,*], h) Find links by source (outgoing edges)
Each Incoming each_by([*,*,t], h) Find links by target (incoming edges)

Example: Create Operation Comparison

Neo4j (from neo4j/create.rs):

CREATE (l:Link {id: $id, source: 0, target: 0})

Doublets (from doublets/create.rs):

let id = self.allocate_next_id();
self.links[id] = Link { id, source: id, target: id };
self.source_index.insert(id, id);
self.target_index.insert(id, id);

Test Plan

  • Library compiles (cargo check --lib)
  • Benchmarks compile (cargo check --benches)
  • CI passes

Fixes #13

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #13
@konard konard self-assigned this Dec 29, 2025
… Doublets

This reorganization makes it crystal clear how the same logic is implemented
in both Doublets and Neo4j, as requested in issue #13.

Key changes:
- lib.rs: Added crate-level documentation explaining the common interface
  (Doublets<T> trait) and how each database implements it
- lib.rs: Added type aliases (DoubletsUnitedVolatile, Neo4jNonTransaction, etc.)
  with detailed documentation showing Cypher equivalents for each operation
- benches/benchmarks/mod.rs: Added module-level documentation listing all
  benchmarked operations and storage backends
- Each benchmark file (create.rs, delete.rs, update.rs, each/*.rs): Added
  documentation explaining:
  - The common interface method being benchmarked
  - How Doublets implements it (direct memory/index operations)
  - How Neo4j implements it (Cypher queries)
  - Time complexity comparisons

The documentation now clearly shows:
1. What interface method is being benchmarked
2. How each database implements that method
3. The equivalent Cypher query for Neo4j operations
4. The underlying storage structure for Doublets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] Reorganize the code, so it will be cristal clear how the same logic is implement in Doublets and in Neo4j Reorganize the code to make it crystal clear how the same logic is implemented in Doublets and Neo4j Dec 29, 2025
@konard konard marked this pull request as ready for review December 29, 2025 16:30
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard
Copy link
Member Author

konard commented Dec 29, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $8.440627 USD
  • Calculated by Anthropic: $5.423159 USD
  • Difference: $-3.017468 (-35.75%)
    📎 Log file uploaded as GitHub Gist (808KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Member Author

konard commented Dec 29, 2025

I want separate files for Neo4j and Doublets for easy to compare structure.

@konard konard marked this pull request as draft December 29, 2025 17:57
@konard
Copy link
Member Author

konard commented Dec 29, 2025

🤖 AI Work Session Started

Starting automated work session at 2025-12-29T17:57:14.854Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

Per user feedback, create separate documentation files for easier comparison:
- doublets_impl.rs: Documents how Doublets implements the common interface
- neo4j_impl.rs: Documents how Neo4j implements the common interface with Cypher

Each file shows the same operations side-by-side for easy structure comparison.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review December 29, 2025 18:22
@konard
Copy link
Member Author

konard commented Dec 29, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $2.903512 USD
  • Calculated by Anthropic: $1.961857 USD
  • Difference: $-0.941655 (-32.43%)
    📎 Log file uploaded as GitHub Gist (385KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Member Author

konard commented Dec 29, 2025

🔄 Auto-restart 1/3

Detected uncommitted changes from previous run. Starting new session to review and commit them.

Uncommitted files:

?? cargo-check-benches.log
?? cargo-check.log
?? issue-view.txt
?? pr-conversation-comments.json
?? pr-diff.txt
?? pr-review-comments.json
?? pr-view.txt

Auto-restart will stop after changes are committed or after 2 more iterations. Please wait until working session will end and give your feedback.

@konard
Copy link
Member Author

konard commented Dec 29, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.298158 USD
  • Calculated by Anthropic: $0.762007 USD
  • Difference: $-0.536151 (-41.30%)
    📎 Log file uploaded as GitHub Gist (648KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Member Author

konard commented Dec 29, 2025

Do we really use our new separate implementation, or we just duplicated the code?

I want clear separation between Neo4j and Doublets logic in all files, so each file that contains both logics should be split into two.

@konard konard marked this pull request as draft December 29, 2025 18:43
@konard
Copy link
Member Author

konard commented Dec 29, 2025

🤖 AI Work Session Started

Starting automated work session at 2025-12-29T18:43:01.478Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

Per user feedback, reorganize benchmarks to have clear separation between
Neo4j and Doublets implementations. Each file now contains only one
database's benchmarks for easy side-by-side comparison.

New structure:
- rust/benches/benchmarks/neo4j/     - All Neo4j benchmarks
- rust/benches/benchmarks/doublets/  - All Doublets benchmarks

Each directory has the same structure:
- create.rs, update.rs, delete.rs - CRUD operations
- each/all.rs, identity.rs, concrete.rs, outgoing.rs, incoming.rs - Query operations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review December 29, 2025 19:12
@konard
Copy link
Member Author

konard commented Dec 29, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $6.974089 USD
  • Calculated by Anthropic: $4.548438 USD
  • Difference: $-2.425650 (-34.78%)
    📎 Log file uploaded as GitHub Gist (663KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Member Author

konard commented Dec 29, 2025

🔄 Auto-restart 1/3

Detected uncommitted changes from previous run. Starting new session to review and commit them.

Uncommitted files:

?? pr-14-conversation-comments.json
?? pr-14-details.json
?? pr-14-review-comments.json
?? rust/cargo-check-benches.log
?? rust/cargo-check-lib.log

Auto-restart will stop after changes are committed or after 2 more iterations. Please wait until working session will end and give your feedback.

Addresses user feedback requesting clear separation of Neo4j and Doublets
logic. The benched.rs file contained mixed implementations for both databases.

Changes:
- Removed rust/src/benched.rs (contained both Neo4j and Doublets impls)
- Added rust/src/benched/mod.rs with common Benched trait
- Added rust/src/benched/doublets_benched.rs with Doublets implementations
- Added rust/src/benched/neo4j_benched.rs with Neo4j implementations

This provides complete separation between Neo4j and Doublets code across
all source files for easier side-by-side comparison.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard
Copy link
Member Author

konard commented Dec 29, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $4.431444 USD
  • Calculated by Anthropic: $2.832516 USD
  • Difference: $-1.598927 (-36.08%)
    📎 Log file uploaded as GitHub Gist (1140KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 7fcdba1 into main Dec 31, 2025
1 check passed
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.

Reorganize the code, so it will be cristal clear how the same logic is implement in Doublets and in Neo4j

1 participant