hindsight-client 0.1.3__py3-none-any.whl → 0.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hindsight_client/__init__.py +49 -4
- hindsight_client/hindsight_client.py +19 -10
- {hindsight_client-0.1.3.dist-info → hindsight_client-0.1.5.dist-info}/METADATA +1 -1
- {hindsight_client-0.1.3.dist-info → hindsight_client-0.1.5.dist-info}/RECORD +5 -5
- {hindsight_client-0.1.3.dist-info → hindsight_client-0.1.5.dist-info}/WHEEL +0 -0
hindsight_client/__init__.py
CHANGED
|
@@ -15,8 +15,8 @@ Example:
|
|
|
15
15
|
print(result.success)
|
|
16
16
|
|
|
17
17
|
# Search memories
|
|
18
|
-
|
|
19
|
-
for r in results:
|
|
18
|
+
response = client.recall(bank_id="alice", query="What does Alice like?")
|
|
19
|
+
for r in response.results:
|
|
20
20
|
print(r.text)
|
|
21
21
|
|
|
22
22
|
# Generate contextual answer
|
|
@@ -29,14 +29,59 @@ from .hindsight_client import Hindsight
|
|
|
29
29
|
|
|
30
30
|
# Re-export response types for convenient access
|
|
31
31
|
from hindsight_client_api.models.retain_response import RetainResponse
|
|
32
|
-
from hindsight_client_api.models.recall_response import RecallResponse
|
|
33
|
-
from hindsight_client_api.models.recall_result import RecallResult
|
|
32
|
+
from hindsight_client_api.models.recall_response import RecallResponse as _RecallResponse
|
|
33
|
+
from hindsight_client_api.models.recall_result import RecallResult as _RecallResult
|
|
34
34
|
from hindsight_client_api.models.reflect_response import ReflectResponse
|
|
35
35
|
from hindsight_client_api.models.reflect_fact import ReflectFact
|
|
36
36
|
from hindsight_client_api.models.list_memory_units_response import ListMemoryUnitsResponse
|
|
37
37
|
from hindsight_client_api.models.bank_profile_response import BankProfileResponse
|
|
38
38
|
from hindsight_client_api.models.disposition_traits import DispositionTraits
|
|
39
39
|
|
|
40
|
+
|
|
41
|
+
# Add cleaner __repr__ and __iter__ for REPL usability
|
|
42
|
+
def _recall_result_repr(self):
|
|
43
|
+
text_preview = self.text[:80] + "..." if len(self.text) > 80 else self.text
|
|
44
|
+
return f"RecallResult(id='{self.id[:8]}...', type='{self.type}', text='{text_preview}')"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _recall_response_repr(self):
|
|
48
|
+
count = len(self.results) if self.results else 0
|
|
49
|
+
extras = []
|
|
50
|
+
if self.trace:
|
|
51
|
+
extras.append("trace=True")
|
|
52
|
+
if self.entities:
|
|
53
|
+
extras.append(f"entities={len(self.entities)}")
|
|
54
|
+
if self.chunks:
|
|
55
|
+
extras.append(f"chunks={len(self.chunks)}")
|
|
56
|
+
extras_str = ", " + ", ".join(extras) if extras else ""
|
|
57
|
+
return f"RecallResponse({count} results{extras_str})"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _recall_response_iter(self):
|
|
61
|
+
"""Iterate directly over results for convenience."""
|
|
62
|
+
return iter(self.results or [])
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _recall_response_len(self):
|
|
66
|
+
"""Return number of results."""
|
|
67
|
+
return len(self.results) if self.results else 0
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _recall_response_getitem(self, index):
|
|
71
|
+
"""Access results by index."""
|
|
72
|
+
return self.results[index]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
_RecallResult.__repr__ = _recall_result_repr
|
|
76
|
+
_RecallResponse.__repr__ = _recall_response_repr
|
|
77
|
+
_RecallResponse.__iter__ = _recall_response_iter
|
|
78
|
+
_RecallResponse.__len__ = _recall_response_len
|
|
79
|
+
_RecallResponse.__getitem__ = _recall_response_getitem
|
|
80
|
+
|
|
81
|
+
# Re-export with patched repr
|
|
82
|
+
RecallResult = _RecallResult
|
|
83
|
+
RecallResponse = _RecallResponse
|
|
84
|
+
|
|
40
85
|
__all__ = [
|
|
41
86
|
"Hindsight",
|
|
42
87
|
# Response types
|
|
@@ -50,7 +50,9 @@ class Hindsight:
|
|
|
50
50
|
client.retain(bank_id="alice", content="Alice loves AI")
|
|
51
51
|
|
|
52
52
|
# Recall memories
|
|
53
|
-
|
|
53
|
+
response = client.recall(bank_id="alice", query="What does Alice like?")
|
|
54
|
+
for r in response.results:
|
|
55
|
+
print(r.text)
|
|
54
56
|
|
|
55
57
|
# Generate contextual answer
|
|
56
58
|
answer = client.reflect(bank_id="alice", query="What are my interests?")
|
|
@@ -125,8 +127,8 @@ class Hindsight:
|
|
|
125
127
|
|
|
126
128
|
Args:
|
|
127
129
|
bank_id: The memory bank ID
|
|
128
|
-
items: List of memory items with 'content' and optional 'timestamp', 'context', 'metadata'
|
|
129
|
-
document_id: Optional document ID for grouping memories
|
|
130
|
+
items: List of memory items with 'content' and optional 'timestamp', 'context', 'metadata', 'document_id'
|
|
131
|
+
document_id: Optional document ID for grouping memories (applied to items that don't have their own)
|
|
130
132
|
retain_async: If True, process asynchronously in background (default: False)
|
|
131
133
|
|
|
132
134
|
Returns:
|
|
@@ -138,13 +140,14 @@ class Hindsight:
|
|
|
138
140
|
timestamp=item.get("timestamp"),
|
|
139
141
|
context=item.get("context"),
|
|
140
142
|
metadata=item.get("metadata"),
|
|
143
|
+
# Use item's document_id if provided, otherwise fall back to batch-level document_id
|
|
144
|
+
document_id=item.get("document_id") or document_id,
|
|
141
145
|
)
|
|
142
146
|
for item in items
|
|
143
147
|
]
|
|
144
148
|
|
|
145
149
|
request_obj = retain_request.RetainRequest(
|
|
146
150
|
items=memory_items,
|
|
147
|
-
document_id=document_id,
|
|
148
151
|
async_=retain_async,
|
|
149
152
|
)
|
|
150
153
|
|
|
@@ -161,6 +164,8 @@ class Hindsight:
|
|
|
161
164
|
query_timestamp: Optional[str] = None,
|
|
162
165
|
include_entities: bool = False,
|
|
163
166
|
max_entity_tokens: int = 500,
|
|
167
|
+
include_chunks: bool = False,
|
|
168
|
+
max_chunk_tokens: int = 8192,
|
|
164
169
|
) -> RecallResponse:
|
|
165
170
|
"""
|
|
166
171
|
Recall memories using semantic similarity.
|
|
@@ -175,14 +180,17 @@ class Hindsight:
|
|
|
175
180
|
query_timestamp: Optional ISO format date string (e.g., '2023-05-30T23:40:00')
|
|
176
181
|
include_entities: Include entity observations in results (default: False)
|
|
177
182
|
max_entity_tokens: Maximum tokens for entity observations (default: 500)
|
|
183
|
+
include_chunks: Include raw text chunks in results (default: False)
|
|
184
|
+
max_chunk_tokens: Maximum tokens for chunks (default: 8192)
|
|
178
185
|
|
|
179
186
|
Returns:
|
|
180
|
-
RecallResponse with results, optional entities, and optional trace
|
|
187
|
+
RecallResponse with results, optional entities, optional chunks, and optional trace
|
|
181
188
|
"""
|
|
182
|
-
from hindsight_client_api.models import include_options, entity_include_options
|
|
189
|
+
from hindsight_client_api.models import include_options, entity_include_options, chunk_include_options
|
|
183
190
|
|
|
184
191
|
include_opts = include_options.IncludeOptions(
|
|
185
|
-
entities=entity_include_options.EntityIncludeOptions(max_tokens=max_entity_tokens) if include_entities else None
|
|
192
|
+
entities=entity_include_options.EntityIncludeOptions(max_tokens=max_entity_tokens) if include_entities else None,
|
|
193
|
+
chunks=chunk_include_options.ChunkIncludeOptions(max_tokens=max_chunk_tokens) if include_chunks else None,
|
|
186
194
|
)
|
|
187
195
|
|
|
188
196
|
request_obj = recall_request.RecallRequest(
|
|
@@ -277,8 +285,8 @@ class Hindsight:
|
|
|
277
285
|
|
|
278
286
|
Args:
|
|
279
287
|
bank_id: The memory bank ID
|
|
280
|
-
items: List of memory items with 'content' and optional 'timestamp', 'context', 'metadata'
|
|
281
|
-
document_id: Optional document ID for grouping memories
|
|
288
|
+
items: List of memory items with 'content' and optional 'timestamp', 'context', 'metadata', 'document_id'
|
|
289
|
+
document_id: Optional document ID for grouping memories (applied to items that don't have their own)
|
|
282
290
|
retain_async: If True, process asynchronously in background (default: False)
|
|
283
291
|
|
|
284
292
|
Returns:
|
|
@@ -290,13 +298,14 @@ class Hindsight:
|
|
|
290
298
|
timestamp=item.get("timestamp"),
|
|
291
299
|
context=item.get("context"),
|
|
292
300
|
metadata=item.get("metadata"),
|
|
301
|
+
# Use item's document_id if provided, otherwise fall back to batch-level document_id
|
|
302
|
+
document_id=item.get("document_id") or document_id,
|
|
293
303
|
)
|
|
294
304
|
for item in items
|
|
295
305
|
]
|
|
296
306
|
|
|
297
307
|
request_obj = retain_request.RetainRequest(
|
|
298
308
|
items=memory_items,
|
|
299
|
-
document_id=document_id,
|
|
300
309
|
async_=retain_async,
|
|
301
310
|
)
|
|
302
311
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
hindsight_client/__init__.py,sha256=
|
|
2
|
-
hindsight_client/hindsight_client.py,sha256=
|
|
1
|
+
hindsight_client/__init__.py,sha256=PyDJ4UVKmtRN5OeBs0-rl-tUtqS8OoX53qvejKGC3JU,3114
|
|
2
|
+
hindsight_client/hindsight_client.py,sha256=tKqeqcbYAgCFIgYBgcyKZi-DYC10FF9suA1VhooOrxU,13481
|
|
3
3
|
hindsight_client_api/__init__.py,sha256=7hfGgOu50_bmmuoz4-e4JVqubo5W39g_p3HHgaWZGRs,5941
|
|
4
4
|
hindsight_client_api/api_client.py,sha256=gO_s4kVFGPJMawvNcdoqbpqptHIIKELylVni48b7rqU,27860
|
|
5
5
|
hindsight_client_api/api_response.py,sha256=eMxw1mpmJcoGZ3gs9z6jM4oYoZ10Gjk333s9sKxGv7s,652
|
|
@@ -126,6 +126,6 @@ hindsight_client_api/test/test_retain_response.py,sha256=L_83q5aYZAb9mZhHwF7WAe4
|
|
|
126
126
|
hindsight_client_api/test/test_update_disposition_request.py,sha256=bHQG7SqMD_KESLs61kVOTknYH-flvX5UjW9yJ9UK3RI,1550
|
|
127
127
|
hindsight_client_api/test/test_validation_error.py,sha256=FiG2lcCSznxrbqRk2rcKv1ctpin0gGM5YGReZWMRnkw,1549
|
|
128
128
|
hindsight_client_api/test/test_validation_error_loc_inner.py,sha256=Cy-VdSn1aBCRzpiI-2OSCrK376C5eHDywvbF16KNhMQ,1398
|
|
129
|
-
hindsight_client-0.1.
|
|
130
|
-
hindsight_client-0.1.
|
|
131
|
-
hindsight_client-0.1.
|
|
129
|
+
hindsight_client-0.1.5.dist-info/METADATA,sha256=Em5Vh-0LfFwgpsGd4USYCopnv0TxmqiHcqSMdqU6aN4,598
|
|
130
|
+
hindsight_client-0.1.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
131
|
+
hindsight_client-0.1.5.dist-info/RECORD,,
|
|
File without changes
|