mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 03:31:02 +02:00
Fixing query stuff
This commit is contained in:
parent
179285e186
commit
8c38dc30ff
8 changed files with 27 additions and 33 deletions
|
|
@ -44,21 +44,14 @@ class Processor(GraphEmbeddingsQueryService):
|
|||
|
||||
try:
|
||||
|
||||
v = msg.value()
|
||||
|
||||
# Sender-produced ID
|
||||
id = msg.properties()["id"]
|
||||
|
||||
print(f"Handling input {id}...", flush=True)
|
||||
|
||||
entity_set = set()
|
||||
entities = []
|
||||
|
||||
for vec in v.vectors:
|
||||
for vec in msg.vectors:
|
||||
|
||||
dim = len(vec)
|
||||
collection = (
|
||||
"t_" + v.user + "_" + v.collection + "_" +
|
||||
"t_" + msg.user + "_" + msg.collection + "_" +
|
||||
str(dim)
|
||||
)
|
||||
|
||||
|
|
@ -67,7 +60,7 @@ class Processor(GraphEmbeddingsQueryService):
|
|||
search_result = self.qdrant.query_points(
|
||||
collection_name=collection,
|
||||
query=vec,
|
||||
limit=v.limit * 2,
|
||||
limit=msg.limit * 2,
|
||||
with_payload=True,
|
||||
).points
|
||||
|
||||
|
|
@ -80,10 +73,10 @@ class Processor(GraphEmbeddingsQueryService):
|
|||
entities.append(ent)
|
||||
|
||||
# Keep adding entities until limit
|
||||
if len(entity_set) >= v.limit: break
|
||||
if len(entity_set) >= msg.limit: break
|
||||
|
||||
# Keep adding entities until limit
|
||||
if len(entity_set) >= v.limit: break
|
||||
if len(entity_set) >= msg.limit: break
|
||||
|
||||
ents2 = []
|
||||
|
||||
|
|
|
|||
|
|
@ -59,11 +59,6 @@ class Processor(TriplesQueryService):
|
|||
)
|
||||
self.table = table
|
||||
|
||||
# Sender-produced ID
|
||||
id = msg.properties()["id"]
|
||||
|
||||
print(f"Handling input {id}...", flush=True)
|
||||
|
||||
triples = []
|
||||
|
||||
if query.s is not None:
|
||||
|
|
@ -138,8 +133,6 @@ class Processor(TriplesQueryService):
|
|||
|
||||
return triples
|
||||
|
||||
print("Done.", flush=True)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print(f"Exception: {e}")
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ class Query:
|
|||
if self.verbose:
|
||||
print("Get entities...", flush=True)
|
||||
|
||||
print("HERE>", query, flush=True)
|
||||
|
||||
entities = await self.rag.graph_embeddings_client.query(
|
||||
vectors=vectors, limit=self.entity_limit,
|
||||
user=self.user, collection=self.collection,
|
||||
|
|
@ -47,7 +49,7 @@ class Query:
|
|||
print("ENT>", entities, flush=True)
|
||||
|
||||
entities = [
|
||||
e.value
|
||||
str(e)
|
||||
for e in entities
|
||||
]
|
||||
|
||||
|
|
@ -72,7 +74,7 @@ class Query:
|
|||
self.rag.label_cache[e] = e
|
||||
return e
|
||||
|
||||
self.rag.label_cache[e] = res[0].o.value
|
||||
self.rag.label_cache[e] = str(res[0].o)
|
||||
return self.rag.label_cache[e]
|
||||
|
||||
async def follow_edges(self, ent, subgraph, path_length):
|
||||
|
|
@ -93,10 +95,10 @@ class Query:
|
|||
|
||||
for triple in res:
|
||||
subgraph.add(
|
||||
(triple.s.value, triple.p.value, triple.o.value)
|
||||
(str(triple.s), str(triple.p), str(triple.o))
|
||||
)
|
||||
if path_length > 1:
|
||||
await self.follow_edges(triple.o.value, subgraph, path_length-1)
|
||||
await self.follow_edges(str(triple.o), subgraph, path_length-1)
|
||||
|
||||
res = await self.rag.triples_client.request(
|
||||
user=self.user, collection=self.collection,
|
||||
|
|
@ -106,7 +108,7 @@ class Query:
|
|||
|
||||
for triple in res:
|
||||
subgraph.add(
|
||||
(triple.s.value, triple.p.value, triple.o.value)
|
||||
(str(triple.s), str(triple.p), str(triple.o))
|
||||
)
|
||||
|
||||
res = await self.rag.triples_client.request(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue