• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

orneryd / NornicDB / 23451608288

23 Mar 2026 05:42PM UTC coverage: 87.728% (-0.3%) from 88.019%
23451608288

push

github

orneryd
perf(cypher): restore safe UNION fast paths and reduce subquery/cache allocations

re-enable UNION subquery shortcuts with strict safety guards
keep correlated batched lookup path active for CALL-with-WITH patterns
harden traversal fallback pruning with fail-open behavior and chained-pattern safety
reduce allocation pressure in hot paths:
replace strings.Fields-based query normalization with single-pass whitespace compaction
optimize CALL/UNION row dedupe key formatting
preserve correctness for regression cases:
chained traversal property-access queries
duplicate rows vs DISTINCT semantics

526 of 942 new or added lines in 8 files covered. (55.84%)

88 existing lines in 13 files now uncovered.

103046 of 117461 relevant lines covered (87.73%)

1.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.49
/pkg/cypher/vector_query_embed_cache.go
1
package cypher
2

3
import (
4
        "context"
5
        "fmt"
6
        "strings"
7
)
8

9
const maxVectorQueryEmbedCacheEntries = 2048
10

11
func canonicalizeVectorQueryText(text string) string {
1✔
12
        trimmed := strings.TrimSpace(text)
1✔
13
        if trimmed == "" {
1✔
NEW
14
                return ""
×
NEW
15
        }
×
16
        // Normalize to improve cache hit-rate for semantically equivalent queries
17
        // that only differ in casing/spacing.
18
        return strings.Join(strings.Fields(strings.ToLower(trimmed)), " ")
1✔
19
}
20

21
func cloneFloat32Slice(src []float32) []float32 {
1✔
22
        if len(src) == 0 {
2✔
23
                return nil
1✔
24
        }
1✔
25
        out := make([]float32, len(src))
1✔
26
        copy(out, src)
1✔
27
        return out
1✔
28
}
29

30
func (e *StorageExecutor) embedVectorQueryText(ctx context.Context, text string) ([]float32, error) {
1✔
31
        if e.embedder == nil {
1✔
NEW
32
                return nil, fmt.Errorf("no embedder configured")
×
NEW
33
        }
×
34
        key := canonicalizeVectorQueryText(text)
1✔
35
        if key == "" {
1✔
NEW
36
                return embedQueryChunked(ctx, e.embedder, text)
×
NEW
37
        }
×
38

39
        e.vectorQueryEmbedMu.Lock()
1✔
40
        if vec, ok := e.vectorQueryEmbedCache[key]; ok {
2✔
41
                e.vectorQueryEmbedMu.Unlock()
1✔
42
                return cloneFloat32Slice(vec), nil
1✔
43
        }
1✔
44
        if in, ok := e.vectorQueryEmbedInflight[key]; ok {
1✔
NEW
45
                e.vectorQueryEmbedMu.Unlock()
×
NEW
46
                select {
×
NEW
47
                case <-ctx.Done():
×
NEW
48
                        return nil, ctx.Err()
×
NEW
49
                case <-in.done:
×
NEW
50
                        if in.err != nil {
×
NEW
51
                                return nil, in.err
×
NEW
52
                        }
×
NEW
53
                        return cloneFloat32Slice(in.vec), nil
×
54
                }
55
        }
56

57
        in := &vectorEmbedInflight{done: make(chan struct{})}
1✔
58
        e.vectorQueryEmbedInflight[key] = in
1✔
59
        e.vectorQueryEmbedMu.Unlock()
1✔
60

1✔
61
        vec, err := embedQueryChunked(ctx, e.embedder, key)
1✔
62
        in.vec = cloneFloat32Slice(vec)
1✔
63
        in.err = err
1✔
64

1✔
65
        e.vectorQueryEmbedMu.Lock()
1✔
66
        delete(e.vectorQueryEmbedInflight, key)
1✔
67
        if err == nil && len(in.vec) > 0 {
2✔
68
                if len(e.vectorQueryEmbedCache) >= maxVectorQueryEmbedCacheEntries {
1✔
NEW
69
                        // Keep eviction policy simple and deterministic: clear on capacity.
×
NEW
70
                        e.vectorQueryEmbedCache = make(map[string][]float32, 512)
×
NEW
71
                }
×
72
                e.vectorQueryEmbedCache[key] = cloneFloat32Slice(in.vec)
1✔
73
        }
74
        close(in.done)
1✔
75
        e.vectorQueryEmbedMu.Unlock()
1✔
76

1✔
77
        if err != nil {
2✔
78
                return nil, err
1✔
79
        }
1✔
80
        return cloneFloat32Slice(in.vec), nil
1✔
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc