trustgraph-base .chunks / .documents confusion in the API (#485)

Back-ported to 1.2 from 1.3 (#481)

* trustgraph-base .chunks / .documents confusion in the API

* Added tests, fixed test failures in code

* Fix file dup error

* Fix contract error
This commit is contained in:
cybermaggedon 2025-09-03 16:50:54 +01:00 committed by GitHub
parent 056c702515
commit 0ae39aef7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 639 additions and 9 deletions

View file

@ -27,7 +27,7 @@ class DocumentEmbeddingsClient(RequestResponse):
if resp.error:
raise RuntimeError(resp.error.message)
return resp.documents
return resp.chunks
class DocumentEmbeddingsClientSpec(RequestResponseSpec):
def __init__(

View file

@ -57,7 +57,7 @@ class DocumentEmbeddingsQueryService(FlowProcessor):
docs = await self.query_document_embeddings(request)
logger.debug("Sending document embeddings query response...")
r = DocumentEmbeddingsResponse(documents=docs, error=None)
r = DocumentEmbeddingsResponse(chunks=docs, error=None)
await flow("response").send(r, properties={"id": id})
logger.debug("Document embeddings query request completed")
@ -73,7 +73,7 @@ class DocumentEmbeddingsQueryService(FlowProcessor):
type = "document-embeddings-query-error",
message = str(e),
),
response=None,
chunks=None,
)
await flow("response").send(r, properties={"id": id})

View file

@ -47,5 +47,5 @@ class DocumentEmbeddingsClient(BaseClient):
return self.call(
user=user, collection=collection,
vectors=vectors, limit=limit, timeout=timeout
).documents
).chunks

View file

@ -36,10 +36,10 @@ class DocumentEmbeddingsResponseTranslator(MessageTranslator):
def from_pulsar(self, obj: DocumentEmbeddingsResponse) -> Dict[str, Any]:
result = {}
if obj.documents:
result["documents"] = [
doc.decode("utf-8") if isinstance(doc, bytes) else doc
for doc in obj.documents
if obj.chunks is not None:
result["chunks"] = [
chunk.decode("utf-8") if isinstance(chunk, bytes) else chunk
for chunk in obj.chunks
]
return result

View file

@ -45,4 +45,11 @@ class DocumentEmbeddingsRequest(Record):
class DocumentEmbeddingsResponse(Record):
error = Error()
chunks = Array(String())
chunks = Array(String())
document_embeddings_request_queue = topic(
"non-persistent://trustgraph/document-embeddings-request"
)
document_embeddings_response_queue = topic(
"non-persistent://trustgraph/document-embeddings-response"
)