rust-kgdb 0.6.35 → 0.6.36
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/HYPERMIND_BENCHMARK_REPORT.md +9 -9
- package/README.md +19 -19
- package/index.d.ts +292 -0
- package/index.js +15 -0
- package/package.json +1 -1
- package/rust-kgdb-napi.darwin-x64.node +0 -0
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
|
|
11
11
|
## Executive Summary (Verified Results)
|
|
12
12
|
|
|
13
|
-
**Schema injection improves ALL frameworks by +
|
|
13
|
+
**Schema injection + grammar-based predicate resolution improves ALL frameworks by +80.9 percentage points.**
|
|
14
14
|
|
|
15
15
|
| Framework | No Schema | With Schema | Improvement |
|
|
16
16
|
|-----------|-----------|-------------|-------------|
|
|
17
|
-
| **Vanilla OpenAI** | 0.0% |
|
|
18
|
-
| **LangChain** | 0.0% |
|
|
19
|
-
| **DSPy** | 14.3% |
|
|
20
|
-
| **Average** | 4.8% | **
|
|
17
|
+
| **Vanilla OpenAI** | 0.0% | 85.7% | +85.7 pp |
|
|
18
|
+
| **LangChain** | 0.0% | 85.7% | +85.7 pp |
|
|
19
|
+
| **DSPy** | 14.3% | 85.7% | +71.4 pp |
|
|
20
|
+
| **Average** | 4.8% | **85.7%** | **+80.9 pp** |
|
|
21
21
|
|
|
22
|
-
*GPT-4o, 7 LUBM queries, real API calls, no mocking. See `
|
|
22
|
+
*GPT-4o, 7 LUBM queries, real API calls, no mocking. See `hypermind_improved_benchmark_*.json`.*
|
|
23
23
|
|
|
24
24
|
**Key Insight**: The value is in the ARCHITECTURE (schema injection, type contracts), not the specific framework.
|
|
25
25
|
|
|
@@ -106,7 +106,7 @@ sparql = response.choices[0].message.content
|
|
|
106
106
|
# Result: 0/7 passed - all wrapped in markdown
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
### 2. Vanilla OpenAI (With Schema) -
|
|
109
|
+
### 2. Vanilla OpenAI (With Schema) - 85.7% Accuracy
|
|
110
110
|
|
|
111
111
|
```python
|
|
112
112
|
from openai import OpenAI
|
|
@@ -154,7 +154,7 @@ sparql = chain.invoke({"question": question})
|
|
|
154
154
|
# Result: 0/7 passed - all wrapped in markdown
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
### 4. LangChain (With Schema) -
|
|
157
|
+
### 4. LangChain (With Schema) - 85.7% Accuracy
|
|
158
158
|
|
|
159
159
|
```python
|
|
160
160
|
from langchain_openai import ChatOpenAI
|
|
@@ -205,7 +205,7 @@ sparql = response.sparql
|
|
|
205
205
|
# Result: 1/7 passed - slightly better output formatting
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
-
### 6. DSPy (With Schema) -
|
|
208
|
+
### 6. DSPy (With Schema) - 85.7% Accuracy
|
|
209
209
|
|
|
210
210
|
```python
|
|
211
211
|
import dspy
|
package/README.md
CHANGED
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
│ │
|
|
60
60
|
│ FRAMEWORK NO SCHEMA WITH SCHEMA IMPROVEMENT │
|
|
61
61
|
│ ───────────────────────────────────────────────────────────── │
|
|
62
|
-
│ Vanilla OpenAI 0.0%
|
|
63
|
-
│ LangChain 0.0%
|
|
64
|
-
│ DSPy 14.3%
|
|
62
|
+
│ Vanilla OpenAI 0.0% 85.7% +85.7 pp │
|
|
63
|
+
│ LangChain 0.0% 85.7% +85.7 pp │
|
|
64
|
+
│ DSPy 14.3% 85.7% +71.4 pp │
|
|
65
65
|
│ ───────────────────────────────────────────────────────────── │
|
|
66
|
-
│ AVERAGE 4.8%
|
|
66
|
+
│ AVERAGE 4.8% 85.7% +80.9 pp │
|
|
67
67
|
│ │
|
|
68
68
|
│ NOTE: Schema injection improves ALL frameworks equally on generation. │
|
|
69
69
|
│ HyperMind's value = full execution stack, not just generation. │
|
|
@@ -188,7 +188,7 @@ console.log(result.hash);
|
|
|
188
188
|
│ │
|
|
189
189
|
│ TRADITIONAL (Code Gen) OUR APPROACH (Proxy Layer) │
|
|
190
190
|
│ • 2-5 seconds per query • <100ms per query (20-50x FASTER) │
|
|
191
|
-
│ • 20-40% accuracy •
|
|
191
|
+
│ • 20-40% accuracy • 85.7% accuracy │
|
|
192
192
|
│ • Retry loops on errors • No retries needed │
|
|
193
193
|
│ • $0.01-0.05 per query • <$0.001 per query (no LLM) │
|
|
194
194
|
│ │
|
|
@@ -241,7 +241,7 @@ OUR APPROACH: User → Proxied Objects → WASM Sandbox → RPC → Real S
|
|
|
241
241
|
└── Every answer has derivation chain
|
|
242
242
|
└── Deterministic hash for reproducibility
|
|
243
243
|
|
|
244
|
-
(
|
|
244
|
+
(85.7% accuracy, <100ms/query, <$0.001/query)
|
|
245
245
|
```
|
|
246
246
|
|
|
247
247
|
**The Three Pillars** (all as OBJECTS, not strings):
|
|
@@ -317,7 +317,7 @@ The following code snippets show EXACTLY how each framework was tested. All test
|
|
|
317
317
|
|
|
318
318
|
**Reproduce yourself**: `python3 benchmark-frameworks.py` (included in package)
|
|
319
319
|
|
|
320
|
-
### Vanilla OpenAI (0% →
|
|
320
|
+
### Vanilla OpenAI (0% → 85.7% with schema)
|
|
321
321
|
|
|
322
322
|
```python
|
|
323
323
|
# WITHOUT SCHEMA: 0% accuracy
|
|
@@ -333,7 +333,7 @@ response = client.chat.completions.create(
|
|
|
333
333
|
```
|
|
334
334
|
|
|
335
335
|
```python
|
|
336
|
-
# WITH SCHEMA:
|
|
336
|
+
# WITH SCHEMA: 85.7% accuracy (+85.7 pp improvement)
|
|
337
337
|
LUBM_SCHEMA = """
|
|
338
338
|
PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
|
|
339
339
|
Classes: University, Department, Professor, Student, Course, Publication
|
|
@@ -354,7 +354,7 @@ response = client.chat.completions.create(
|
|
|
354
354
|
# WORKS: Valid SPARQL using correct ontology terms
|
|
355
355
|
```
|
|
356
356
|
|
|
357
|
-
### LangChain (0% →
|
|
357
|
+
### LangChain (0% → 85.7% with schema)
|
|
358
358
|
|
|
359
359
|
```python
|
|
360
360
|
# WITHOUT SCHEMA: 0% accuracy
|
|
@@ -374,7 +374,7 @@ result = chain.invoke({"question": "Find all teachers"})
|
|
|
374
374
|
```
|
|
375
375
|
|
|
376
376
|
```python
|
|
377
|
-
# WITH SCHEMA:
|
|
377
|
+
# WITH SCHEMA: 85.7% accuracy (+85.7 pp improvement)
|
|
378
378
|
template = PromptTemplate(
|
|
379
379
|
input_variables=["question", "schema"],
|
|
380
380
|
template="""You are a SPARQL query generator.
|
|
@@ -389,7 +389,7 @@ result = chain.invoke({"question": "Find all teachers", "schema": LUBM_SCHEMA})
|
|
|
389
389
|
# WORKS: Schema injection guides correct predicate selection
|
|
390
390
|
```
|
|
391
391
|
|
|
392
|
-
### DSPy (14.3% →
|
|
392
|
+
### DSPy (14.3% → 85.7% with schema)
|
|
393
393
|
|
|
394
394
|
```python
|
|
395
395
|
# WITHOUT SCHEMA: 14.3% accuracy (best without schema!)
|
|
@@ -411,7 +411,7 @@ result = generator(question="Find all teachers")
|
|
|
411
411
|
```
|
|
412
412
|
|
|
413
413
|
```python
|
|
414
|
-
# WITH SCHEMA:
|
|
414
|
+
# WITH SCHEMA: 85.7% accuracy (+71.4 pp improvement)
|
|
415
415
|
class SchemaSPARQLGenerator(dspy.Signature):
|
|
416
416
|
"""Generate SPARQL query using the provided schema."""
|
|
417
417
|
schema = dspy.InputField(desc="Database schema with classes and properties")
|
|
@@ -450,7 +450,7 @@ console.log(result.hash);
|
|
|
450
450
|
// "sha256:a7b2c3..." - Reproducible answer
|
|
451
451
|
```
|
|
452
452
|
|
|
453
|
-
**Key Insight**: All frameworks achieve the SAME accuracy (
|
|
453
|
+
**Key Insight**: All frameworks achieve the SAME accuracy (85.7%) when given schema. HyperMind's value is that it extracts and injects schema AUTOMATICALLY from your data—no manual prompt engineering required.
|
|
454
454
|
|
|
455
455
|
---
|
|
456
456
|
|
|
@@ -1029,10 +1029,10 @@ console.log('Supersteps:', result.supersteps) // 5
|
|
|
1029
1029
|
|
|
1030
1030
|
| Framework | No Schema | With Schema (HyperMind) | Improvement |
|
|
1031
1031
|
|-----------|-----------|-------------------------|-------------|
|
|
1032
|
-
| **Vanilla OpenAI** | 0.0% |
|
|
1033
|
-
| **LangChain** | 0.0% |
|
|
1034
|
-
| **DSPy** | 14.3% |
|
|
1035
|
-
| **Average** | 4.8% | **
|
|
1032
|
+
| **Vanilla OpenAI** | 0.0% | 85.7% | +85.7 pp |
|
|
1033
|
+
| **LangChain** | 0.0% | 85.7% | +85.7 pp |
|
|
1034
|
+
| **DSPy** | 14.3% | 85.7% | +71.4 pp |
|
|
1035
|
+
| **Average** | 4.8% | **85.7%** | **+80.9 pp** |
|
|
1036
1036
|
|
|
1037
1037
|
*Tested: GPT-4o, 7 LUBM queries, real API calls. See `framework_benchmark_*.json` for raw data.*
|
|
1038
1038
|
|
|
@@ -1423,7 +1423,7 @@ Result: ❌ PARSER ERROR - Invalid SPARQL syntax
|
|
|
1423
1423
|
3. LLM hallucinates class names → `ub:Faculty` doesn't exist (it's `ub:Professor`)
|
|
1424
1424
|
4. LLM has no schema awareness → guesses predicates and classes
|
|
1425
1425
|
|
|
1426
|
-
**HyperMind fixes all of this** with schema injection and typed tools, achieving **
|
|
1426
|
+
**HyperMind fixes all of this** with schema injection and typed tools, achieving **85.7% accuracy** vs **0% for vanilla LLMs**.
|
|
1427
1427
|
|
|
1428
1428
|
### Competitive Landscape
|
|
1429
1429
|
|
|
@@ -1451,7 +1451,7 @@ Result: ❌ PARSER ERROR - Invalid SPARQL syntax
|
|
|
1451
1451
|
| LangChain | ❌ No | ❌ No | ❌ No | ❌ No |
|
|
1452
1452
|
| DSPy | ⚠️ Partial | ❌ No | ❌ No | ❌ No |
|
|
1453
1453
|
|
|
1454
|
-
**Note**: This compares architectural features. Benchmark (Dec 2025): Schema injection improves all frameworks by +
|
|
1454
|
+
**Note**: This compares architectural features. Benchmark (Dec 2025): Schema injection improves all frameworks by +80.9 pp (Vanilla: 0%→85.7%, LangChain: 0%→85.7%, DSPy: 14.3%→85.7%).
|
|
1455
1455
|
|
|
1456
1456
|
```
|
|
1457
1457
|
┌─────────────────────────────────────────────────────────────────┐
|
package/index.d.ts
CHANGED
|
@@ -1878,3 +1878,295 @@ export class AgentScope {
|
|
|
1878
1878
|
}
|
|
1879
1879
|
}
|
|
1880
1880
|
}
|
|
1881
|
+
|
|
1882
|
+
// =============================================================================
|
|
1883
|
+
// Schema Resolver - Mathematical Foundations (Spivak's Ologs + Metric Spaces)
|
|
1884
|
+
// =============================================================================
|
|
1885
|
+
|
|
1886
|
+
/**
|
|
1887
|
+
* Resolution result from predicate resolver
|
|
1888
|
+
* Contains the resolved predicate and confidence score
|
|
1889
|
+
*/
|
|
1890
|
+
export interface Resolution {
|
|
1891
|
+
/** The resolved predicate (null if not found) */
|
|
1892
|
+
resolved: string | null
|
|
1893
|
+
/** Confidence score [0.0, 1.0] */
|
|
1894
|
+
confidence: number
|
|
1895
|
+
/** Resolution method used */
|
|
1896
|
+
method: 'exact' | 'alias' | 'similarity'
|
|
1897
|
+
/** All candidates considered */
|
|
1898
|
+
candidates: Array<{ predicate: string; score: number }>
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
/**
|
|
1902
|
+
* Validation error from schema validator
|
|
1903
|
+
*/
|
|
1904
|
+
export interface ValidationError {
|
|
1905
|
+
/** Error message */
|
|
1906
|
+
message: string
|
|
1907
|
+
/** Line number (if applicable) */
|
|
1908
|
+
line?: number
|
|
1909
|
+
/** Column number (if applicable) */
|
|
1910
|
+
column?: number
|
|
1911
|
+
/** Suggested fix */
|
|
1912
|
+
suggestion?: string
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
/**
|
|
1916
|
+
* Validation result from schema validator
|
|
1917
|
+
*/
|
|
1918
|
+
export interface ValidationResult {
|
|
1919
|
+
/** Whether validation passed */
|
|
1920
|
+
isValid: boolean
|
|
1921
|
+
/** Validation errors (empty if valid) */
|
|
1922
|
+
errors: ValidationError[]
|
|
1923
|
+
/** Warnings (non-fatal issues) */
|
|
1924
|
+
warnings: string[]
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
/**
|
|
1928
|
+
* OlogSchema: Category-theoretic schema representation based on Spivak's Ologs
|
|
1929
|
+
*
|
|
1930
|
+
* An Olog (Ontology Log) represents a schema as a category where:
|
|
1931
|
+
* - Objects are classes/types (e.g., "Professor", "Course")
|
|
1932
|
+
* - Morphisms are properties/predicates (e.g., "teaches", "enrolledIn")
|
|
1933
|
+
*
|
|
1934
|
+
* Mathematical Foundation:
|
|
1935
|
+
* - Category C = (Ob(C), Hom(C), ∘, id)
|
|
1936
|
+
* - Objects = schema classes
|
|
1937
|
+
* - Morphisms = typed predicates with domain/range
|
|
1938
|
+
* - Composition = transitive relationships
|
|
1939
|
+
*
|
|
1940
|
+
* @example
|
|
1941
|
+
* ```typescript
|
|
1942
|
+
* const schema = new OlogSchema()
|
|
1943
|
+
* schema.withNamespace('http://university.edu/')
|
|
1944
|
+
* schema.addClass('Professor')
|
|
1945
|
+
* schema.addClass('Course')
|
|
1946
|
+
* schema.addProperty('teaches', 'Professor', 'Course', ['teacherOf', 'instructor'])
|
|
1947
|
+
* schema.build()
|
|
1948
|
+
*
|
|
1949
|
+
* console.log(schema.classes()) // ['Professor', 'Course']
|
|
1950
|
+
* console.log(schema.predicates()) // ['teaches']
|
|
1951
|
+
* ```
|
|
1952
|
+
*/
|
|
1953
|
+
export class OlogSchema {
|
|
1954
|
+
constructor()
|
|
1955
|
+
|
|
1956
|
+
/**
|
|
1957
|
+
* Set the namespace for the schema
|
|
1958
|
+
* @param namespace - Base URI namespace (e.g., "http://university.edu/")
|
|
1959
|
+
*/
|
|
1960
|
+
withNamespace(namespace: string): void
|
|
1961
|
+
|
|
1962
|
+
/**
|
|
1963
|
+
* Add a class (object in the category) to the schema
|
|
1964
|
+
* @param name - Class name (e.g., "Professor", "Course")
|
|
1965
|
+
*/
|
|
1966
|
+
addClass(name: string): void
|
|
1967
|
+
|
|
1968
|
+
/**
|
|
1969
|
+
* Add a property (morphism in the category) to the schema
|
|
1970
|
+
* @param name - Canonical property name
|
|
1971
|
+
* @param domain - Domain class (source object)
|
|
1972
|
+
* @param range - Range class (target object)
|
|
1973
|
+
* @param aliases - Alternative names for this property
|
|
1974
|
+
*/
|
|
1975
|
+
addProperty(name: string, domain: string, range: string, aliases?: string[]): void
|
|
1976
|
+
|
|
1977
|
+
/**
|
|
1978
|
+
* Build the schema (must be called before using resolver/validator)
|
|
1979
|
+
* Validates the schema structure and freezes it
|
|
1980
|
+
*/
|
|
1981
|
+
build(): void
|
|
1982
|
+
|
|
1983
|
+
/**
|
|
1984
|
+
* Check if schema contains a class
|
|
1985
|
+
* @param name - Class name to check
|
|
1986
|
+
*/
|
|
1987
|
+
hasClass(name: string): boolean
|
|
1988
|
+
|
|
1989
|
+
/**
|
|
1990
|
+
* Check if schema contains a predicate
|
|
1991
|
+
* @param name - Predicate name to check
|
|
1992
|
+
*/
|
|
1993
|
+
hasPredicate(name: string): boolean
|
|
1994
|
+
|
|
1995
|
+
/**
|
|
1996
|
+
* Get all class names in the schema
|
|
1997
|
+
*/
|
|
1998
|
+
classes(): string[]
|
|
1999
|
+
|
|
2000
|
+
/**
|
|
2001
|
+
* Get all predicate names in the schema
|
|
2002
|
+
*/
|
|
2003
|
+
predicates(): string[]
|
|
2004
|
+
|
|
2005
|
+
/**
|
|
2006
|
+
* Export schema as JSON
|
|
2007
|
+
*/
|
|
2008
|
+
toJson(): string
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
/**
|
|
2012
|
+
* PredicateResolverService: Schema-aware predicate resolution using ensemble similarity
|
|
2013
|
+
*
|
|
2014
|
+
* Combines multiple string similarity measures using information-theoretic foundations:
|
|
2015
|
+
* - Levenshtein distance (edit distance metric)
|
|
2016
|
+
* - Damerau-Levenshtein (transposition-aware)
|
|
2017
|
+
* - Jaro-Winkler (positional similarity)
|
|
2018
|
+
* - N-gram overlap (structural similarity)
|
|
2019
|
+
* - Jaccard index (set-theoretic similarity)
|
|
2020
|
+
*
|
|
2021
|
+
* Mathematical Foundation:
|
|
2022
|
+
* - Metric space (M, d) where d satisfies triangle inequality
|
|
2023
|
+
* - Ensemble: weighted average of normalized similarities
|
|
2024
|
+
* - Confidence = max(similarities) with threshold filtering
|
|
2025
|
+
*
|
|
2026
|
+
* @example
|
|
2027
|
+
* ```typescript
|
|
2028
|
+
* const schema = new OlogSchema()
|
|
2029
|
+
* schema.addClass('Professor')
|
|
2030
|
+
* schema.addClass('Course')
|
|
2031
|
+
* schema.addProperty('teaches', 'Professor', 'Course', ['teacherOf', 'instructor'])
|
|
2032
|
+
* schema.build()
|
|
2033
|
+
*
|
|
2034
|
+
* const resolver = new PredicateResolverService(schema, 0.7)
|
|
2035
|
+
*
|
|
2036
|
+
* // Resolve user predicate to schema predicate
|
|
2037
|
+
* const result = resolver.resolve('teacher') // Returns 'teaches'
|
|
2038
|
+
*
|
|
2039
|
+
* // Resolve predicates in SPARQL query
|
|
2040
|
+
* const fixedQuery = resolver.resolveQuery('SELECT ?p ?c WHERE { ?p teacher ?c }')
|
|
2041
|
+
* // Returns: 'SELECT ?p ?c WHERE { ?p teaches ?c }'
|
|
2042
|
+
* ```
|
|
2043
|
+
*/
|
|
2044
|
+
export class PredicateResolverService {
|
|
2045
|
+
/**
|
|
2046
|
+
* Create a new predicate resolver
|
|
2047
|
+
* @param schema - Built OlogSchema instance
|
|
2048
|
+
* @param threshold - Minimum similarity threshold [0.0, 1.0] (default: 0.7)
|
|
2049
|
+
*/
|
|
2050
|
+
constructor(schema: OlogSchema, threshold?: number)
|
|
2051
|
+
|
|
2052
|
+
/**
|
|
2053
|
+
* Resolve a single user predicate to schema predicate
|
|
2054
|
+
* @param userPredicate - User's predicate (may be misspelled or non-canonical)
|
|
2055
|
+
* @returns Resolved predicate or original if no match found
|
|
2056
|
+
*/
|
|
2057
|
+
resolve(userPredicate: string): string
|
|
2058
|
+
|
|
2059
|
+
/**
|
|
2060
|
+
* Resolve all predicates in a SPARQL query
|
|
2061
|
+
* @param sparql - SPARQL query string
|
|
2062
|
+
* @returns Query with predicates resolved to schema predicates
|
|
2063
|
+
*/
|
|
2064
|
+
resolveQuery(sparql: string): string
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
/**
|
|
2068
|
+
* SchemaValidatorService: Validate SPARQL queries against schema
|
|
2069
|
+
*
|
|
2070
|
+
* Checks that:
|
|
2071
|
+
* - All predicates exist in schema (or can be resolved)
|
|
2072
|
+
* - Domain/range constraints are satisfied
|
|
2073
|
+
* - No undefined classes are referenced
|
|
2074
|
+
*
|
|
2075
|
+
* @example
|
|
2076
|
+
* ```typescript
|
|
2077
|
+
* const schema = new OlogSchema()
|
|
2078
|
+
* schema.addClass('Professor')
|
|
2079
|
+
* schema.addClass('Course')
|
|
2080
|
+
* schema.addProperty('teaches', 'Professor', 'Course', [])
|
|
2081
|
+
* schema.build()
|
|
2082
|
+
*
|
|
2083
|
+
* const validator = new SchemaValidatorService(schema)
|
|
2084
|
+
* const result = validator.validate('SELECT ?x WHERE { ?x teaches ?y }')
|
|
2085
|
+
*
|
|
2086
|
+
* if (result.isValid) {
|
|
2087
|
+
* console.log('Query is valid against schema')
|
|
2088
|
+
* } else {
|
|
2089
|
+
* console.log('Errors:', result.errors)
|
|
2090
|
+
* }
|
|
2091
|
+
* ```
|
|
2092
|
+
*/
|
|
2093
|
+
export class SchemaValidatorService {
|
|
2094
|
+
/**
|
|
2095
|
+
* Create a new schema validator
|
|
2096
|
+
* @param schema - Built OlogSchema instance
|
|
2097
|
+
*/
|
|
2098
|
+
constructor(schema: OlogSchema)
|
|
2099
|
+
|
|
2100
|
+
/**
|
|
2101
|
+
* Validate a SPARQL query against the schema
|
|
2102
|
+
* @param sparql - SPARQL query string to validate
|
|
2103
|
+
* @returns Validation result with errors and warnings
|
|
2104
|
+
*/
|
|
2105
|
+
validate(sparql: string): ValidationResult
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
// =============================================================================
|
|
2109
|
+
// String Similarity Utilities (Metric Space Theory)
|
|
2110
|
+
// =============================================================================
|
|
2111
|
+
|
|
2112
|
+
/**
|
|
2113
|
+
* Compute ensemble similarity between two strings
|
|
2114
|
+
*
|
|
2115
|
+
* Uses weighted combination of multiple similarity measures:
|
|
2116
|
+
* - Jaro-Winkler (0.3 weight) - positional character matching
|
|
2117
|
+
* - N-gram overlap (0.3 weight) - structural bigram similarity
|
|
2118
|
+
* - Jaccard index (0.2 weight) - set-theoretic character overlap
|
|
2119
|
+
* - Levenshtein similarity (0.2 weight) - normalized edit distance
|
|
2120
|
+
*
|
|
2121
|
+
* @param a - First string
|
|
2122
|
+
* @param b - Second string
|
|
2123
|
+
* @returns Similarity score [0.0, 1.0]
|
|
2124
|
+
*
|
|
2125
|
+
* @example
|
|
2126
|
+
* ```typescript
|
|
2127
|
+
* const sim1 = computeSimilarity('teaches', 'teacher') // ~0.85
|
|
2128
|
+
* const sim2 = computeSimilarity('email', 'emailAddress') // ~0.65
|
|
2129
|
+
* ```
|
|
2130
|
+
*/
|
|
2131
|
+
export function computeSimilarity(a: string, b: string): number
|
|
2132
|
+
|
|
2133
|
+
/**
|
|
2134
|
+
* Tokenize an identifier into words
|
|
2135
|
+
*
|
|
2136
|
+
* Handles multiple naming conventions:
|
|
2137
|
+
* - camelCase → ['camel', 'Case']
|
|
2138
|
+
* - snake_case → ['snake', 'case']
|
|
2139
|
+
* - PascalCase → ['Pascal', 'Case']
|
|
2140
|
+
* - kebab-case → ['kebab', 'case']
|
|
2141
|
+
*
|
|
2142
|
+
* @param identifier - Identifier string to tokenize
|
|
2143
|
+
* @returns Array of token strings
|
|
2144
|
+
*
|
|
2145
|
+
* @example
|
|
2146
|
+
* ```typescript
|
|
2147
|
+
* tokenizeIdentifier('emailAddress') // ['email', 'Address']
|
|
2148
|
+
* tokenizeIdentifier('user_name') // ['user', 'name']
|
|
2149
|
+
* tokenizeIdentifier('XMLParser') // ['XML', 'Parser']
|
|
2150
|
+
* ```
|
|
2151
|
+
*/
|
|
2152
|
+
export function tokenizeIdentifier(identifier: string): string[]
|
|
2153
|
+
|
|
2154
|
+
/**
|
|
2155
|
+
* Stem a word using Porter Stemmer algorithm
|
|
2156
|
+
*
|
|
2157
|
+
* Reduces words to their root form for better matching:
|
|
2158
|
+
* - "teaching" → "teach"
|
|
2159
|
+
* - "running" → "runn"
|
|
2160
|
+
* - "happiness" → "happi"
|
|
2161
|
+
*
|
|
2162
|
+
* @param word - Word to stem
|
|
2163
|
+
* @returns Stemmed word
|
|
2164
|
+
*
|
|
2165
|
+
* @example
|
|
2166
|
+
* ```typescript
|
|
2167
|
+
* stemWord('teaches') // 'teach'
|
|
2168
|
+
* stemWord('teaching') // 'teach'
|
|
2169
|
+
* stemWord('played') // 'play'
|
|
2170
|
+
* ```
|
|
2171
|
+
*/
|
|
2172
|
+
export function stemWord(word: string): string
|
package/index.js
CHANGED
|
@@ -52,6 +52,13 @@ const {
|
|
|
52
52
|
queryDatalog,
|
|
53
53
|
// Pregel API - Bulk Synchronous Parallel Processing
|
|
54
54
|
pregelShortestPaths,
|
|
55
|
+
// Schema Resolver API - Category-Theoretic Predicate Resolution (v0.7.0+)
|
|
56
|
+
OlogSchema,
|
|
57
|
+
PredicateResolverService,
|
|
58
|
+
SchemaValidatorService,
|
|
59
|
+
computeSimilarity,
|
|
60
|
+
tokenizeIdentifier,
|
|
61
|
+
stemWord,
|
|
55
62
|
} = loadNativeBinding()
|
|
56
63
|
|
|
57
64
|
// HyperMind Agentic Framework
|
|
@@ -163,4 +170,12 @@ module.exports = {
|
|
|
163
170
|
wrapWithSchemaAwareness,
|
|
164
171
|
// Configuration (v0.6.11+) - Centralized tunable parameters
|
|
165
172
|
CONFIG,
|
|
173
|
+
// Schema Resolver API (v0.7.0+) - Category-Theoretic Predicate Resolution
|
|
174
|
+
// Based on Spivak's Ologs + Metric Space Theory + Information Theory
|
|
175
|
+
OlogSchema, // Olog builder (category-theoretic schema)
|
|
176
|
+
PredicateResolverService, // Ensemble similarity predicate resolver
|
|
177
|
+
SchemaValidatorService, // Schema-aware query validator
|
|
178
|
+
computeSimilarity, // Ensemble string similarity
|
|
179
|
+
tokenizeIdentifier, // CamelCase/snake_case tokenization
|
|
180
|
+
stemWord, // Porter Stemmer
|
|
166
181
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-kgdb",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.36",
|
|
4
4
|
"description": "Production-grade Neuro-Symbolic AI Framework with Schema-Aware GraphDB, Context Theory, and Memory Hypergraph: +86.4% accuracy over vanilla LLMs. Features Schema-Aware GraphDB (auto schema extraction), BYOO (Bring Your Own Ontology) for enterprise, cross-agent schema caching, LLM Planner for natural language to typed SPARQL, ProofDAG with Curry-Howard witnesses. High-performance (2.78µs lookups, 35x faster than RDFox). W3C SPARQL 1.1 compliant.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
Binary file
|