agredadb 1.0.0
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/agreda.proto +52 -0
- package/index.js +44 -0
- package/package.json +11 -0
package/agreda.proto
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package agreda;
|
|
3
|
+
|
|
4
|
+
service Agreda {
|
|
5
|
+
rpc Insert (InsertRequest) returns (InsertResponse);
|
|
6
|
+
rpc InsertBatch (InsertBatchRequest) returns (InsertResponse);
|
|
7
|
+
rpc Query (QueryRequest) returns (QueryResponse);
|
|
8
|
+
|
|
9
|
+
// NUEVO: Búsqueda Vectorial Real (Nearest Neighbor Search)
|
|
10
|
+
rpc Search (SearchRequest) returns (SearchResponse);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
message InsertRequest {
|
|
14
|
+
string table = 1;
|
|
15
|
+
string json_data = 2;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
message InsertBatchRequest {
|
|
19
|
+
string table = 1;
|
|
20
|
+
repeated string json_data_list = 2;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
message InsertResponse {
|
|
24
|
+
bool success = 1;
|
|
25
|
+
string message = 2;
|
|
26
|
+
uint32 records_processed = 3;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
message QueryRequest {
|
|
30
|
+
string sql = 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
message QueryResponse {
|
|
34
|
+
bytes arrow_ipc_stream = 1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
message SearchRequest {
|
|
38
|
+
string table = 1;
|
|
39
|
+
repeated float vector = 2; // El vector a buscar (embedding)
|
|
40
|
+
uint32 limit = 3; // Top K (ej. 10)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
message SearchResponse {
|
|
44
|
+
// Lista de JSONs con los resultados ordenados por similitud
|
|
45
|
+
repeated SearchResult results = 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
message SearchResult {
|
|
49
|
+
string id = 1;
|
|
50
|
+
float score = 2; // Similitud Coseno (0.0 a 1.0)
|
|
51
|
+
string json_data = 3;
|
|
52
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const grpc = require('@grpc/grpc-js');
|
|
2
|
+
const protoLoader = require('@grpc/proto-loader');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const PROTO_PATH = path.join(__dirname, 'agreda.proto');
|
|
6
|
+
|
|
7
|
+
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
|
|
8
|
+
keepCase: true,
|
|
9
|
+
longs: String,
|
|
10
|
+
enums: String,
|
|
11
|
+
defaults: True,
|
|
12
|
+
oneofs: True
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const agredaProto = grpc.loadPackageDefinition(packageDefinition).agreda;
|
|
16
|
+
|
|
17
|
+
class AgredaClient {
|
|
18
|
+
constructor(host = 'localhost:19999') {
|
|
19
|
+
this.client = new agredaProto.Agreda(host, grpc.credentials.createInsecure());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
insert(table, data) {
|
|
23
|
+
const jsonData = typeof data === 'string' ? data : JSON.stringify(data);
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
this.client.Insert({ table, json_data: jsonData }, (err, resp) => {
|
|
26
|
+
if (err) reject(err);
|
|
27
|
+
else resolve(resp);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
search(table, vector, limit = 10) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
this.client.Search({ table, vector, limit }, (err, resp) => {
|
|
35
|
+
if (err) reject(err);
|
|
36
|
+
else resolve(resp.results);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
connect: (host) => new AgredaClient(host)
|
|
44
|
+
};
|
package/package.json
ADDED