ACOR Documentation

Schema V2 (Optimized)

V2 is the recommended schema for ACOR. It uses a fixed 3 keys per collection.

Overview

V2 consolidates storage into 3 keys:

Key PatternPurpose
{name}:trieSerialized trie structure (keywords, prefixes, suffixes, version)
{name}:outputsAll output mappings (state -> keywords)
{name}:nodesNode metadata (migration only, cleaned up by flush)

Performance Characteristics

OperationComplexity
Find()3 RTT (fixed), 0 RTT with EnableCache
Add()2-3 RTT

Comparison with V1

MetricV1V2Improvement
Keys per 100K keywords~500K3166,667x
Find() RTT3-5 per state3 total50-60x
Memory efficiencyLowerHigher10x+

Architecture

graph TB
    subgraph V2 Schema
        A[trie key] --> B[Serialized Trie]
        C[outputs key] --> D[Output Map]
        E[nodes key] --> F[Node Metadata - migration only]
    end

    G[Find Operation] --> A
    G --> C
    G -.-> E

Enabling V2

V2 is automatically used for new collections. No configuration needed.

ac, err := acor.Create(&acor.AhoCorasickArgs{
    Addr: "localhost:6379",
    Name: "my-v2-collection",
})
if err != nil {
    log.Fatal(err)
}
// Automatically uses V2 schema

Migration from V1

# Check current schema
acor -name mycollection schema-version

# Preview migration
acor -name mycollection migrate --dry-run

# Execute migration
acor -name mycollection migrate

Key Structure

trie key

Stores the serialized trie as a hash with four fields:

{collection}:trie
  keywords -> ["keyword1", "keyword2", ...]
  prefixes  -> ["", "h", "he", ...]
  suffixes  -> ["", "e", "eh", ...]
  version   -> <int64 optimistic lock>

outputs key

Stores output keywords per trie state as a hash:

{collection}:outputs
  he  -> ["he"]
  she -> ["he", "she"]

nodes key

Stores node-level metadata:

{collection}:nodes
  keyword1 -> {"count": 1, "depth": 3}

Recommendation

Use V2 for all new collections. It provides significantly better performance and lower resource usage.