-
Notifications
You must be signed in to change notification settings - Fork 0
Partial Candle + RWKV Integration and SurrealDB Fixes #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iberi22
wants to merge
1
commit into
main
Choose a base branch
from
feat/candle-rwkv-integration-4915240440993110878
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize}; | |
| use surrealdb::engine::local::{Db, Mem, SurrealKv}; | ||
| use surrealdb::sql::Thing; | ||
| use surrealdb::Surreal; | ||
| use surrealdb::opt::SurrealValue; | ||
| use synapse_core::{error::Error, error::Result, MemoryNode, MemoryPort, NodeType, SearchResult}; | ||
| use std::sync::Arc; | ||
| use tokio::sync::OnceCell; | ||
|
|
@@ -28,8 +29,10 @@ struct MemoryRecord { | |
| loop_level: u8, | ||
| } | ||
|
|
||
| impl SurrealValue for MemoryRecord {} | ||
|
|
||
| /// Search result from SurrealDB vector query. | ||
| #[derive(Debug, Deserialize)] | ||
| #[derive(Debug, Serialize, Deserialize)] | ||
| struct VectorSearchResult { | ||
| id: Thing, | ||
| content: String, | ||
|
|
@@ -46,6 +49,52 @@ struct VectorSearchResult { | |
| distance: f32, | ||
| } | ||
|
|
||
| impl SurrealValue for VectorSearchResult {} | ||
|
|
||
| /// Internal record type for SurrealDB queries with ID. | ||
| #[derive(Debug, Serialize, Deserialize)] | ||
| struct RecordWithId { | ||
| id: Thing, | ||
| content: String, | ||
| layer: u8, | ||
| node_type: String, | ||
| created_at: i64, | ||
| updated_at: i64, | ||
| embedding: Vec<f32>, | ||
| metadata: String, | ||
| namespace: String, | ||
| source: String, | ||
| holographic_data: Option<Vec<u8>>, | ||
| loop_level: u8, | ||
| } | ||
|
|
||
| impl SurrealValue for RecordWithId {} | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| struct CountResult { | ||
| count: usize, | ||
| } | ||
|
|
||
| impl SurrealValue for CountResult {} | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| struct LayerResult { | ||
| id: Thing, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| content: String, | ||
| layer: u8, | ||
| node_type: String, | ||
| created_at: i64, | ||
| updated_at: i64, | ||
| embedding: Vec<f32>, | ||
| metadata: String, | ||
| namespace: String, | ||
| source: String, | ||
| holographic_data: Option<Vec<u8>>, | ||
| loop_level: u8, | ||
| } | ||
|
|
||
| impl SurrealValue for LayerResult {} | ||
|
|
||
| /// SurrealDB adapter for vector storage with graph support. | ||
| pub struct SurrealDbAdapter { | ||
| db: Arc<Surreal<Db>>, | ||
|
|
@@ -392,22 +441,6 @@ impl MemoryPort for SurrealDbAdapter { | |
| .await | ||
| .map_err(|e| Error::System(format!("Get by layer failed: {}", e)))?; | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct LayerResult { | ||
| id: Thing, | ||
| content: String, | ||
| layer: u8, | ||
| node_type: String, | ||
| created_at: i64, | ||
| updated_at: i64, | ||
| embedding: Vec<f32>, | ||
| metadata: String, | ||
| namespace: String, | ||
| source: String, | ||
| holographic_data: Option<Vec<u8>>, | ||
| loop_level: u8, | ||
| } | ||
|
|
||
| let results: Vec<LayerResult> = response | ||
| .take(0) | ||
| .map_err(|e| Error::System(format!("Failed to parse layer results: {}", e)))?; | ||
|
|
@@ -467,11 +500,6 @@ impl MemoryPort for SurrealDbAdapter { | |
| .await | ||
| .map_err(|e| Error::System(format!("Count failed: {}", e)))?; | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct CountResult { | ||
| count: usize, | ||
| } | ||
|
|
||
| let result: Option<CountResult> = response | ||
| .take(0) | ||
| .map_err(|e| Error::System(format!("Failed to parse count: {}", e)))?; | ||
|
|
@@ -504,11 +532,6 @@ impl MemoryPort for SurrealDbAdapter { | |
| .await | ||
| .map_err(|e| Error::System(format!("Count by layer failed: {}", e)))?; | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct CountResult { | ||
| count: usize, | ||
| } | ||
|
|
||
| let result: Option<CountResult> = response | ||
| .take(0) | ||
| .map_err(|e| Error::System(format!("Failed to parse layer count: {}", e)))?; | ||
|
|
@@ -542,22 +565,6 @@ impl MemoryPort for SurrealDbAdapter { | |
| .await | ||
| .map_err(|e| Error::System(e.to_string()))?; | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct RecordWithId { | ||
| id: Thing, | ||
| content: String, | ||
| layer: u8, | ||
| node_type: String, | ||
| created_at: i64, | ||
| updated_at: i64, | ||
| embedding: Vec<f32>, | ||
| metadata: String, | ||
| namespace: String, | ||
| source: String, | ||
| holographic_data: Option<Vec<u8>>, | ||
| loop_level: u8, | ||
| } | ||
|
|
||
| let record_result: surrealdb::Result<Option<RecordWithId>> = response.take(0); | ||
| let record = record_result.map_err(|e| Error::System(e.to_string()))?; | ||
|
|
||
|
|
@@ -587,22 +594,6 @@ impl MemoryPort for SurrealDbAdapter { | |
| let sql = "SELECT * FROM memory_node ORDER BY created_at DESC LIMIT 1"; | ||
| let mut response = self.db.query(sql).await.map_err(|e| Error::System(e.to_string()))?; | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct RecordWithId { | ||
| id: Thing, | ||
| content: String, | ||
| layer: u8, | ||
| node_type: String, | ||
| created_at: i64, | ||
| updated_at: i64, | ||
| embedding: Vec<f32>, | ||
| metadata: String, | ||
| namespace: String, | ||
| source: String, | ||
| holographic_data: Option<Vec<u8>>, | ||
| loop_level: u8, | ||
| } | ||
|
|
||
| let record_result: surrealdb::Result<Option<RecordWithId>> = response.take(0); | ||
| let record = record_result.map_err(|e| Error::System(e.to_string()))?; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions considering
RecordIdinstead ofThingfor SurrealDB v3. Whilesurrealdb::sql::Thingis still functional,surrealdb::RecordIdoffers a more type-safe and idiomatic representation for record IDs in modern SurrealDB usage. Migrating toRecordIdhere would improve type safety and future compatibility. This would involve changing the type of theidfield.