| 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')) |
|
|