File size: 1,566 Bytes
ad90e7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from nzfc_gram_runtime import NZFCGramLongMemoryChat
from nzfc_gram_runtime.nonquant import attach_nonquant_gemma
from nzfc_gram_runtime.cache_profiles import attach_adaptive_kv_cache_generation
from nzfc_gram_runtime.quality import attach_answer_quality_governor
from nzfc_gram_runtime.long_query import attach_long_query_quality_router

MODEL_ID = 'google/gemma-4-E2B-it'

bot = NZFCGramLongMemoryChat(
    repo_dir='.',
    model_id=MODEL_ID,
    memory_db_path='./user_memory_long_query.sqlite3',
    load_model=False,
    require_model=False,
    preload_static_memory=True,
)

attach_nonquant_gemma(bot, model_id=MODEL_ID, device_map='balanced_low_0')
attach_adaptive_kv_cache_generation(bot, default_cache_policy='adaptive')
attach_answer_quality_governor(bot)
attach_long_query_quality_router(bot)

user_id = 'demo_user'
project_id = 'demo_project'

bot.remember(
    'Project memory rule: deleted memories must not be used as evidence.',
    user_id=user_id,
    project_id=project_id,
    session_id='seed',
    tags=['memory_governance'],
    scope='project',
    trust_level=0.95,
)

long_question = (
    'Explain how long-term AI memory should handle exact recall, unsupported private facts, '
    'malicious memory injection, deleted memory, project isolation, user isolation, and context growth. '
    'Answer as an evidence-bound assistant.'
)

res = bot.long_quality_chat(
    long_question,
    user_id=user_id,
    project_id=project_id,
    session_id='query',
    max_new_tokens=180,
)

print(res['answer'])
print(res.get('long_query_router'))