mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 03:31:02 +02:00
Fix embeddings to chunk linkage
This commit is contained in:
parent
7527bd787b
commit
c3471df6ce
5 changed files with 26 additions and 8 deletions
|
|
@ -145,6 +145,7 @@ def derived_entity_triples(
|
||||||
|
|
||||||
# Activity declaration
|
# Activity declaration
|
||||||
_triple(act_uri, RDF_TYPE, _iri(PROV_ACTIVITY)),
|
_triple(act_uri, RDF_TYPE, _iri(PROV_ACTIVITY)),
|
||||||
|
_triple(act_uri, RDFS_LABEL, _literal(f"{component_name} extraction")),
|
||||||
_triple(act_uri, PROV_USED, _iri(parent_uri)),
|
_triple(act_uri, PROV_USED, _iri(parent_uri)),
|
||||||
_triple(act_uri, PROV_WAS_ASSOCIATED_WITH, _iri(agt_uri)),
|
_triple(act_uri, PROV_WAS_ASSOCIATED_WITH, _iri(agt_uri)),
|
||||||
_triple(act_uri, PROV_STARTED_AT_TIME, _literal(timestamp)),
|
_triple(act_uri, PROV_STARTED_AT_TIME, _literal(timestamp)),
|
||||||
|
|
@ -232,6 +233,7 @@ def triple_provenance_triples(
|
||||||
|
|
||||||
# Activity
|
# Activity
|
||||||
_triple(act_uri, RDF_TYPE, _iri(PROV_ACTIVITY)),
|
_triple(act_uri, RDF_TYPE, _iri(PROV_ACTIVITY)),
|
||||||
|
_triple(act_uri, RDFS_LABEL, _literal(f"{component_name} extraction")),
|
||||||
_triple(act_uri, PROV_USED, _iri(chunk_uri)),
|
_triple(act_uri, PROV_USED, _iri(chunk_uri)),
|
||||||
_triple(act_uri, PROV_WAS_ASSOCIATED_WITH, _iri(agt_uri)),
|
_triple(act_uri, PROV_WAS_ASSOCIATED_WITH, _iri(agt_uri)),
|
||||||
_triple(act_uri, PROV_STARTED_AT_TIME, _literal(timestamp)),
|
_triple(act_uri, PROV_STARTED_AT_TIME, _literal(timestamp)),
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,14 @@ class EntityVectors:
|
||||||
max_length=65535,
|
max_length=65535,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
chunk_id_field = FieldSchema(
|
||||||
|
name="chunk_id",
|
||||||
|
dtype=DataType.VARCHAR,
|
||||||
|
max_length=65535,
|
||||||
|
)
|
||||||
|
|
||||||
schema = CollectionSchema(
|
schema = CollectionSchema(
|
||||||
fields = [pkey_field, vec_field, entity_field],
|
fields = [pkey_field, vec_field, entity_field, chunk_id_field],
|
||||||
description = "Graph embedding schema",
|
description = "Graph embedding schema",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -119,17 +125,18 @@ class EntityVectors:
|
||||||
self.collections[(dimension, user, collection)] = collection_name
|
self.collections[(dimension, user, collection)] = collection_name
|
||||||
logger.info(f"Created Milvus collection {collection_name} with dimension {dimension}")
|
logger.info(f"Created Milvus collection {collection_name} with dimension {dimension}")
|
||||||
|
|
||||||
def insert(self, embeds, entity, user, collection):
|
def insert(self, embeds, entity, user, collection, chunk_id=""):
|
||||||
|
|
||||||
dim = len(embeds)
|
dim = len(embeds)
|
||||||
|
|
||||||
if (dim, user, collection) not in self.collections:
|
if (dim, user, collection) not in self.collections:
|
||||||
self.init_collection(dim, user, collection)
|
self.init_collection(dim, user, collection)
|
||||||
|
|
||||||
data = [
|
data = [
|
||||||
{
|
{
|
||||||
"vector": embeds,
|
"vector": embeds,
|
||||||
"entity": entity,
|
"entity": entity,
|
||||||
|
"chunk_id": chunk_id,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ class Processor(CollectionConfigHandler, GraphEmbeddingsStoreService):
|
||||||
self.vecstore.insert(
|
self.vecstore.insert(
|
||||||
vec, entity_value,
|
vec, entity_value,
|
||||||
message.metadata.user,
|
message.metadata.user,
|
||||||
message.metadata.collection
|
message.metadata.collection,
|
||||||
|
chunk_id=entity.chunk_id or "",
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
||||||
|
|
@ -137,11 +137,15 @@ class Processor(CollectionConfigHandler, GraphEmbeddingsStoreService):
|
||||||
# Generate unique ID for each vector
|
# Generate unique ID for each vector
|
||||||
vector_id = str(uuid.uuid4())
|
vector_id = str(uuid.uuid4())
|
||||||
|
|
||||||
|
metadata = {"entity": entity_value}
|
||||||
|
if entity.chunk_id:
|
||||||
|
metadata["chunk_id"] = entity.chunk_id
|
||||||
|
|
||||||
records = [
|
records = [
|
||||||
{
|
{
|
||||||
"id": vector_id,
|
"id": vector_id,
|
||||||
"values": vec,
|
"values": vec,
|
||||||
"metadata": { "entity": entity_value },
|
"metadata": metadata,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,15 +90,19 @@ class Processor(CollectionConfigHandler, GraphEmbeddingsStoreService):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"entity": entity_value,
|
||||||
|
}
|
||||||
|
if entity.chunk_id:
|
||||||
|
payload["chunk_id"] = entity.chunk_id
|
||||||
|
|
||||||
self.qdrant.upsert(
|
self.qdrant.upsert(
|
||||||
collection_name=collection,
|
collection_name=collection,
|
||||||
points=[
|
points=[
|
||||||
PointStruct(
|
PointStruct(
|
||||||
id=str(uuid.uuid4()),
|
id=str(uuid.uuid4()),
|
||||||
vector=vec,
|
vector=vec,
|
||||||
payload={
|
payload=payload,
|
||||||
"entity": entity_value,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue