@ray-db/core 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -51
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,87 +1,113 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ray-db/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
RayDB native bindings for Node.js (and WASI/browser builds), powered by Rust + N-API.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Docs: https://ray-kwaf.vercel.app/docs
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
1. Click **Use this template**.
|
|
10
|
-
2. **Clone** your project.
|
|
11
|
-
3. Run `yarn install` to install dependencies.
|
|
12
|
-
4. Run `yarn napi rename -n [@your-scope/package-name] -b [binary-name]` command under the project folder to rename your package.
|
|
13
|
-
|
|
14
|
-
## Install this test package
|
|
7
|
+
## Install
|
|
15
8
|
|
|
16
9
|
```bash
|
|
17
|
-
|
|
10
|
+
npm install @ray-db/core
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @ray-db/core
|
|
13
|
+
# or
|
|
14
|
+
yarn add @ray-db/core
|
|
18
15
|
```
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
This package ships prebuilt binaries for major platforms. If a prebuild isn't available for your target, you'll need a Rust toolchain to build from source.
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
## Quickstart (graph basics)
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
```ts
|
|
22
|
+
import {
|
|
23
|
+
Database,
|
|
24
|
+
JsTraversalDirection,
|
|
25
|
+
PropType,
|
|
26
|
+
pathConfig,
|
|
27
|
+
traversalStep,
|
|
28
|
+
} from '@ray-db/core'
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
const db = Database.open('example.raydb', { createIfMissing: true })
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
// Transactions are explicit for write operations
|
|
33
|
+
db.begin()
|
|
34
|
+
const alice = db.createNode('user:alice')
|
|
35
|
+
const bob = db.createNode('user:bob')
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
const knows = db.getOrCreateEtype('knows')
|
|
38
|
+
const weight = db.getOrCreatePropkey('weight')
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
db.addEdge(alice, knows, bob)
|
|
33
41
|
|
|
34
|
-
|
|
42
|
+
// Set a typed edge property
|
|
43
|
+
db.setEdgeProp(alice, knows, bob, weight, {
|
|
44
|
+
propType: PropType.Int,
|
|
45
|
+
intValue: 1,
|
|
46
|
+
})
|
|
35
47
|
|
|
36
|
-
|
|
48
|
+
db.commit()
|
|
37
49
|
|
|
38
|
-
|
|
50
|
+
// Traverse
|
|
51
|
+
const oneHop = db.traverseSingle([alice], JsTraversalDirection.Out, knows)
|
|
52
|
+
console.log(oneHop)
|
|
39
53
|
|
|
40
|
-
|
|
54
|
+
// Multi-hop traversal
|
|
55
|
+
const steps = [
|
|
56
|
+
traversalStep(JsTraversalDirection.Out, knows),
|
|
57
|
+
traversalStep(JsTraversalDirection.Out, knows),
|
|
58
|
+
]
|
|
59
|
+
const twoHop = db.traverse([alice], steps)
|
|
60
|
+
console.log(twoHop)
|
|
41
61
|
|
|
42
|
-
|
|
62
|
+
// Pathfinding
|
|
63
|
+
const config = pathConfig(alice, bob)
|
|
64
|
+
config.allowedEdgeTypes = [knows]
|
|
65
|
+
const shortest = db.bfs(config)
|
|
66
|
+
console.log(shortest)
|
|
43
67
|
|
|
44
|
-
|
|
68
|
+
db.close()
|
|
69
|
+
```
|
|
45
70
|
|
|
46
|
-
##
|
|
71
|
+
## Backups and health checks
|
|
47
72
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- Install `yarn@1.x`
|
|
73
|
+
```ts
|
|
74
|
+
import { createBackup, restoreBackup, healthCheck } from '@ray-db/core'
|
|
51
75
|
|
|
52
|
-
|
|
76
|
+
const backup = createBackup(db, 'backups/graph')
|
|
77
|
+
const restoredPath = restoreBackup(backup.path, 'restored/graph')
|
|
53
78
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
79
|
+
const health = healthCheck(db)
|
|
80
|
+
console.log(health.healthy)
|
|
81
|
+
```
|
|
57
82
|
|
|
58
|
-
|
|
83
|
+
## Vector search
|
|
59
84
|
|
|
60
|
-
```
|
|
61
|
-
|
|
85
|
+
```ts
|
|
86
|
+
import { createVectorIndex } from '@ray-db/core'
|
|
62
87
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
88
|
+
const index = createVectorIndex({ dimensions: 3 })
|
|
89
|
+
index.set(1, [0.1, 0.2, 0.3])
|
|
90
|
+
index.set(2, [0.1, 0.25, 0.35])
|
|
91
|
+
index.buildIndex()
|
|
66
92
|
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
const hits = index.search([0.1, 0.2, 0.3], { k: 5 })
|
|
94
|
+
console.log(hits)
|
|
69
95
|
```
|
|
70
96
|
|
|
71
|
-
##
|
|
97
|
+
## Browser/WASI builds
|
|
72
98
|
|
|
73
|
-
|
|
99
|
+
This package exposes a WASI-compatible build via the `browser` export for bundlers, backed by `@ray-db/core-wasm32-wasi`. If you need to import it directly:
|
|
74
100
|
|
|
75
|
-
|
|
101
|
+
```ts
|
|
102
|
+
import { Database } from '@ray-db/core-wasm32-wasi'
|
|
103
|
+
```
|
|
76
104
|
|
|
77
|
-
|
|
105
|
+
## API surface
|
|
78
106
|
|
|
79
|
-
|
|
80
|
-
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
|
|
107
|
+
The Node bindings expose both low-level graph primitives (`Database`) and higher-level APIs (Ray) for schema-driven workflows, plus metrics, backups, traversal, and vector search. For full API details and guides, see the docs:
|
|
81
108
|
|
|
82
|
-
|
|
83
|
-
```
|
|
109
|
+
https://ray-kwaf.vercel.app/docs
|
|
84
110
|
|
|
85
|
-
|
|
111
|
+
## License
|
|
86
112
|
|
|
87
|
-
|
|
113
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-db/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Template project for writing node package with napi-rs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -117,10 +117,10 @@
|
|
|
117
117
|
},
|
|
118
118
|
"packageManager": "yarn@4.12.0",
|
|
119
119
|
"optionalDependencies": {
|
|
120
|
-
"@ray-db/core-win32-x64-msvc": "0.1.
|
|
121
|
-
"@ray-db/core-darwin-x64": "0.1.
|
|
122
|
-
"@ray-db/core-linux-x64-gnu": "0.1.
|
|
123
|
-
"@ray-db/core-darwin-arm64": "0.1.
|
|
124
|
-
"@ray-db/core-wasm32-wasi": "0.1.
|
|
120
|
+
"@ray-db/core-win32-x64-msvc": "0.1.6",
|
|
121
|
+
"@ray-db/core-darwin-x64": "0.1.6",
|
|
122
|
+
"@ray-db/core-linux-x64-gnu": "0.1.6",
|
|
123
|
+
"@ray-db/core-darwin-arm64": "0.1.6",
|
|
124
|
+
"@ray-db/core-wasm32-wasi": "0.1.6"
|
|
125
125
|
}
|
|
126
126
|
}
|