Also GraphRAG service uses this

This commit is contained in:
Cyber MacGeddon 2026-03-09 14:56:51 +00:00
parent 027ef9b85d
commit 9a570036b7
2 changed files with 67 additions and 9 deletions

View file

@ -57,6 +57,61 @@ class TriplesClient(RequestResponse):
return triples
async def query_stream(self, s=None, p=None, o=None, limit=20,
user="trustgraph", collection="default",
batch_size=20, timeout=30,
batch_callback=None):
"""
Streaming triple query - calls callback for each batch as it arrives.
Args:
s, p, o: Triple pattern (None for wildcard)
limit: Maximum total triples to return
user: User/keyspace
collection: Collection name
batch_size: Triples per batch
timeout: Request timeout in seconds
batch_callback: Async callback(batch, is_final) called for each batch
Returns:
List[Triple]: All triples (flattened) if no callback provided
"""
all_triples = []
async def recipient(resp):
if resp.error:
raise RuntimeError(resp.error.message)
batch = [
Triple(to_value(v.s), to_value(v.p), to_value(v.o))
for v in resp.triples
]
if batch_callback:
await batch_callback(batch, resp.is_final)
else:
all_triples.extend(batch)
return resp.is_final
await self.request(
TriplesQueryRequest(
s=from_value(s),
p=from_value(p),
o=from_value(o),
limit=limit,
user=user,
collection=collection,
streaming=True,
batch_size=batch_size,
),
timeout=timeout,
recipient=recipient,
)
if not batch_callback:
return all_triples
class TriplesClientSpec(RequestResponseSpec):
def __init__(
self, request_name, response_name,