@zabaca/lattice 0.1.1 → 0.2.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/README.md +4 -5
- package/dist/cli.js +45 -78
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,13 +108,12 @@ lattice status --verbose # Include detailed change information
|
|
|
108
108
|
|
|
109
109
|
### `lattice search`
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
Semantic search across the knowledge graph.
|
|
112
112
|
|
|
113
113
|
```bash
|
|
114
|
-
lattice search
|
|
115
|
-
lattice search --
|
|
116
|
-
lattice search --
|
|
117
|
-
lattice search --limit 10 # Limit results
|
|
114
|
+
lattice search "query" # Search all entity types
|
|
115
|
+
lattice search --label Technology "query" # Filter by entity label
|
|
116
|
+
lattice search --limit 10 "query" # Limit results (default: 20)
|
|
118
117
|
```
|
|
119
118
|
|
|
120
119
|
### `lattice stats`
|
package/dist/cli.js
CHANGED
|
@@ -2154,7 +2154,7 @@ function registerSyncCommand(program) {
|
|
|
2154
2154
|
};
|
|
2155
2155
|
try {
|
|
2156
2156
|
app = await NestFactory.createApplicationContext(AppModule, {
|
|
2157
|
-
logger: options.verbose ? ["log", "error", "warn"] :
|
|
2157
|
+
logger: options.verbose ? ["log", "error", "warn"] : ["error"]
|
|
2158
2158
|
});
|
|
2159
2159
|
const sync = app.get(SyncService);
|
|
2160
2160
|
if (options.watch && options.dryRun) {
|
|
@@ -2288,7 +2288,7 @@ function registerStatusCommand(program) {
|
|
|
2288
2288
|
let app;
|
|
2289
2289
|
try {
|
|
2290
2290
|
app = await NestFactory2.createApplicationContext(AppModule, {
|
|
2291
|
-
logger:
|
|
2291
|
+
logger: ["error"]
|
|
2292
2292
|
});
|
|
2293
2293
|
const sync = app.get(SyncService);
|
|
2294
2294
|
const manifest = app.get(ManifestService);
|
|
@@ -2354,7 +2354,7 @@ function registerQueryCommands(program) {
|
|
|
2354
2354
|
let app;
|
|
2355
2355
|
try {
|
|
2356
2356
|
app = await NestFactory3.createApplicationContext(AppModule, {
|
|
2357
|
-
logger:
|
|
2357
|
+
logger: ["error"]
|
|
2358
2358
|
});
|
|
2359
2359
|
const graph = app.get(GraphService);
|
|
2360
2360
|
const stats = await graph.getStats();
|
|
@@ -2385,98 +2385,65 @@ Relationship Types (${stats.relationshipTypes.length}):`);
|
|
|
2385
2385
|
process.exit(1);
|
|
2386
2386
|
}
|
|
2387
2387
|
});
|
|
2388
|
-
program.command("search").description("
|
|
2388
|
+
program.command("search <query>").description("Semantic search across the knowledge graph").option("-l, --label <label>", "Filter by entity label (e.g., Technology, Concept, Document)").option("--limit <n>", "Limit results", "20").action(async (query, options) => {
|
|
2389
2389
|
let app;
|
|
2390
2390
|
try {
|
|
2391
2391
|
app = await NestFactory3.createApplicationContext(AppModule, {
|
|
2392
|
-
logger:
|
|
2392
|
+
logger: ["error"]
|
|
2393
2393
|
});
|
|
2394
2394
|
const graph = app.get(GraphService);
|
|
2395
|
-
|
|
2396
|
-
const embedding = app.get(EmbeddingService);
|
|
2397
|
-
const limit2 = Math.min(parseInt(options.limit, 10), 100);
|
|
2398
|
-
try {
|
|
2399
|
-
const queryEmbedding = await embedding.generateEmbedding(options.semantic);
|
|
2400
|
-
const results2 = await graph.vectorSearchAll(queryEmbedding, limit2);
|
|
2401
|
-
console.log(`
|
|
2402
|
-
=== Semantic Search Results for "${options.semantic}" ===
|
|
2403
|
-
`);
|
|
2404
|
-
if (results2.length === 0) {
|
|
2405
|
-
console.log(`No results found with semantic search.
|
|
2406
|
-
`);
|
|
2407
|
-
await app.close();
|
|
2408
|
-
process.exit(0);
|
|
2409
|
-
}
|
|
2410
|
-
results2.forEach((result2, idx) => {
|
|
2411
|
-
console.log(`${idx + 1}. [${result2.label}] ${result2.name}`);
|
|
2412
|
-
if (result2.title) {
|
|
2413
|
-
console.log(` Title: ${result2.title}`);
|
|
2414
|
-
}
|
|
2415
|
-
if (result2.description && result2.label !== "Document") {
|
|
2416
|
-
const desc = result2.description.length > 80 ? result2.description.slice(0, 80) + "..." : result2.description;
|
|
2417
|
-
console.log(` ${desc}`);
|
|
2418
|
-
}
|
|
2419
|
-
console.log(` Similarity: ${(result2.score * 100).toFixed(2)}%`);
|
|
2420
|
-
});
|
|
2421
|
-
console.log();
|
|
2422
|
-
await app.close();
|
|
2423
|
-
process.exit(0);
|
|
2424
|
-
} catch (semanticError) {
|
|
2425
|
-
const errorMsg = semanticError instanceof Error ? semanticError.message : String(semanticError);
|
|
2426
|
-
console.error("Semantic search error:", errorMsg);
|
|
2427
|
-
if (errorMsg.includes("no embeddings") || errorMsg.includes("vector")) {
|
|
2428
|
-
console.log(`
|
|
2429
|
-
Note: Semantic search requires embeddings to be generated first.`);
|
|
2430
|
-
console.log(`Run 'lattice sync' to generate embeddings for documents.
|
|
2431
|
-
`);
|
|
2432
|
-
}
|
|
2433
|
-
await app.close();
|
|
2434
|
-
process.exit(1);
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
let cypher;
|
|
2395
|
+
const embedding = app.get(EmbeddingService);
|
|
2438
2396
|
const limit = Math.min(parseInt(options.limit, 10), 100);
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2397
|
+
const queryEmbedding = await embedding.generateEmbedding(query);
|
|
2398
|
+
let results;
|
|
2399
|
+
if (options.label) {
|
|
2400
|
+
const labelResults = await graph.vectorSearch(options.label, queryEmbedding, limit);
|
|
2401
|
+
results = labelResults.map((r) => ({
|
|
2402
|
+
name: r.name,
|
|
2403
|
+
label: options.label,
|
|
2404
|
+
title: r.title,
|
|
2405
|
+
score: r.score
|
|
2406
|
+
}));
|
|
2449
2407
|
} else {
|
|
2450
|
-
|
|
2408
|
+
results = await graph.vectorSearchAll(queryEmbedding, limit);
|
|
2451
2409
|
}
|
|
2452
|
-
const
|
|
2453
|
-
const results = result.resultSet || [];
|
|
2410
|
+
const labelSuffix = options.label ? ` (${options.label})` : "";
|
|
2454
2411
|
console.log(`
|
|
2455
|
-
=== Search Results
|
|
2412
|
+
=== Semantic Search Results for "${query}"${labelSuffix} ===
|
|
2456
2413
|
`);
|
|
2457
2414
|
if (results.length === 0) {
|
|
2458
|
-
console.log(`No
|
|
2415
|
+
console.log(`No results found.
|
|
2416
|
+
`);
|
|
2417
|
+
if (options.label) {
|
|
2418
|
+
console.log(`Tip: Try without --label to search all entity types.
|
|
2459
2419
|
`);
|
|
2420
|
+
}
|
|
2460
2421
|
await app.close();
|
|
2461
2422
|
process.exit(0);
|
|
2462
2423
|
}
|
|
2463
|
-
results.forEach((
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
console.log(`[${labels}] ${name}`);
|
|
2468
|
-
if (node.properties?.description) {
|
|
2469
|
-
console.log(` Description: ${node.properties.description}`);
|
|
2424
|
+
results.forEach((result, idx) => {
|
|
2425
|
+
console.log(`${idx + 1}. [${result.label}] ${result.name}`);
|
|
2426
|
+
if (result.title) {
|
|
2427
|
+
console.log(` Title: ${result.title}`);
|
|
2470
2428
|
}
|
|
2471
|
-
if (
|
|
2472
|
-
|
|
2429
|
+
if (result.description && result.label !== "Document") {
|
|
2430
|
+
const desc = result.description.length > 80 ? result.description.slice(0, 80) + "..." : result.description;
|
|
2431
|
+
console.log(` ${desc}`);
|
|
2473
2432
|
}
|
|
2433
|
+
console.log(` Similarity: ${(result.score * 100).toFixed(2)}%`);
|
|
2474
2434
|
});
|
|
2475
2435
|
console.log();
|
|
2476
2436
|
await app.close();
|
|
2477
2437
|
process.exit(0);
|
|
2478
2438
|
} catch (error) {
|
|
2479
|
-
|
|
2439
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
2440
|
+
console.error("Error:", errorMsg);
|
|
2441
|
+
if (errorMsg.includes("no embeddings") || errorMsg.includes("vector")) {
|
|
2442
|
+
console.log(`
|
|
2443
|
+
Note: Semantic search requires embeddings to be generated first.`);
|
|
2444
|
+
console.log(`Run 'lattice sync' to generate embeddings for documents.
|
|
2445
|
+
`);
|
|
2446
|
+
}
|
|
2480
2447
|
if (app)
|
|
2481
2448
|
await app.close();
|
|
2482
2449
|
process.exit(1);
|
|
@@ -2486,7 +2453,7 @@ Note: Semantic search requires embeddings to be generated first.`);
|
|
|
2486
2453
|
let app;
|
|
2487
2454
|
try {
|
|
2488
2455
|
app = await NestFactory3.createApplicationContext(AppModule, {
|
|
2489
|
-
logger:
|
|
2456
|
+
logger: ["error"]
|
|
2490
2457
|
});
|
|
2491
2458
|
const graph = app.get(GraphService);
|
|
2492
2459
|
const escapedName = name.replace(/'/g, "\\'");
|
|
@@ -2539,7 +2506,7 @@ Note: Semantic search requires embeddings to be generated first.`);
|
|
|
2539
2506
|
let app;
|
|
2540
2507
|
try {
|
|
2541
2508
|
app = await NestFactory3.createApplicationContext(AppModule, {
|
|
2542
|
-
logger:
|
|
2509
|
+
logger: ["error"]
|
|
2543
2510
|
});
|
|
2544
2511
|
const graph = app.get(GraphService);
|
|
2545
2512
|
const result = await graph.query(query);
|
|
@@ -2561,7 +2528,7 @@ Note: Semantic search requires embeddings to be generated first.`);
|
|
|
2561
2528
|
let app;
|
|
2562
2529
|
try {
|
|
2563
2530
|
app = await NestFactory3.createApplicationContext(AppModule, {
|
|
2564
|
-
logger:
|
|
2531
|
+
logger: ["error"]
|
|
2565
2532
|
});
|
|
2566
2533
|
const graph = app.get(GraphService);
|
|
2567
2534
|
const pathResolver = app.get(PathResolverService);
|
|
@@ -2616,7 +2583,7 @@ function registerValidateCommand(program) {
|
|
|
2616
2583
|
let app;
|
|
2617
2584
|
try {
|
|
2618
2585
|
app = await NestFactory4.createApplicationContext(AppModule, {
|
|
2619
|
-
logger:
|
|
2586
|
+
logger: ["error"]
|
|
2620
2587
|
});
|
|
2621
2588
|
const parser = app.get(DocumentParserService);
|
|
2622
2589
|
console.log(`Validating entities and relationships...
|
|
@@ -2683,7 +2650,7 @@ function registerOntologyCommand(program) {
|
|
|
2683
2650
|
let app;
|
|
2684
2651
|
try {
|
|
2685
2652
|
app = await NestFactory5.createApplicationContext(AppModule, {
|
|
2686
|
-
logger:
|
|
2653
|
+
logger: ["error"]
|
|
2687
2654
|
});
|
|
2688
2655
|
const ontologyService = app.get(OntologyService);
|
|
2689
2656
|
const ontology = await ontologyService.deriveOntology();
|