File size: 1,922 Bytes
59784d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
"""Quick smoke test for Day 1 — run with: python test_extractor.py"""
from extractor import extract_facts
from memory import (
    add_memory,
    delete_all_memories,
    get_all_memories,
    is_duplicate,
    retrieve_relevant,
)


def test_extraction():
    print("=== Fact Extraction ===")
    facts = extract_facts(
        user_message="Hi, my name is Stefan and I'm a Python developer. I love working with AI.",
        bot_reply="Nice to meet you, Stefan! AI development is fascinating.",
    )
    print(f"Extracted {len(facts)} facts:")
    for f in facts:
        print(f"  [{f['type']}] {f['fact']}")
    assert len(facts) > 0, "Extractor returned nothing — check GROQ_API_KEY"
    return facts


def test_memory_store(facts):
    print("\n=== Memory Storage ===")
    delete_all_memories()
    for f in facts:
        mid = add_memory(f["fact"], {"type": f["type"]})
        print(f"  Stored: {f['fact']} (id: {mid[:8]}...)")
    all_memories = get_all_memories()
    print(f"  Total in DB: {len(all_memories)}")
    assert len(all_memories) == len(facts)


def test_retrieval():
    print("\n=== Semantic Retrieval ===")
    results = retrieve_relevant("what does the user do for work?")
    print(f"  Query: 'what does the user do for work?'")
    for r in results:
        print(f"  → {r['fact']}")
    assert len(results) > 0


def test_deduplication():
    print("\n=== Deduplication ===")
    dup = is_duplicate("user's name is Stefan")
    print(f"  is_duplicate('user's name is Stefan'): {dup}  (expected: True)")

    not_dup = is_duplicate("user lives in Tokyo and loves sushi")
    print(f"  is_duplicate('user lives in Tokyo...'): {not_dup}  (expected: False)")

    assert dup is True
    assert not_dup is False


if __name__ == "__main__":
    facts = test_extraction()
    test_memory_store(facts)
    test_retrieval()
    test_deduplication()
    print("\n✓ All Day 1 tests passed")