trustgraph 0.5.1__tar.gz → 0.5.3__tar.gz

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.

Potentially problematic release.


This version of trustgraph might be problematic. Click here for more details.

Files changed (118) hide show
  1. {trustgraph-0.5.1 → trustgraph-0.5.3}/PKG-INFO +11 -8
  2. {trustgraph-0.5.1 → trustgraph-0.5.3}/README.md +8 -6
  3. trustgraph-0.5.3/scripts/concat-parquet +45 -0
  4. trustgraph-0.5.3/scripts/dump-parquet +24 -0
  5. trustgraph-0.5.3/scripts/ge-dump-parquet +6 -0
  6. trustgraph-0.5.3/scripts/load-graph-embeddings +145 -0
  7. trustgraph-0.5.3/scripts/load-triples +144 -0
  8. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/loader +2 -2
  9. trustgraph-0.5.3/scripts/triples-dump-parquet +6 -0
  10. {trustgraph-0.5.1 → trustgraph-0.5.3}/setup.py +8 -1
  11. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/base/base_processor.py +10 -10
  12. trustgraph-0.5.3/trustgraph/dump/graph_embeddings/parquet/processor.py +87 -0
  13. trustgraph-0.5.3/trustgraph/dump/graph_embeddings/parquet/writer.py +94 -0
  14. trustgraph-0.5.3/trustgraph/dump/triples/parquet/__init__.py +3 -0
  15. trustgraph-0.5.3/trustgraph/dump/triples/parquet/processor.py +87 -0
  16. trustgraph-0.5.3/trustgraph/dump/triples/parquet/writer.py +96 -0
  17. trustgraph-0.5.3/trustgraph/embeddings/ollama/__init__.py +3 -0
  18. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/embeddings/vectorize/vectorize.py +4 -1
  19. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/embeddings_client.py +13 -6
  20. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/graph_rag.py +9 -2
  21. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/graph_rag_client.py +12 -4
  22. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/kg/extract_definitions/extract.py +7 -1
  23. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/kg/extract_relationships/extract.py +8 -1
  24. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/llm_client.py +12 -6
  25. trustgraph-0.5.3/trustgraph/storage/__init__.py +0 -0
  26. trustgraph-0.5.3/trustgraph/storage/graph_embeddings/__init__.py +0 -0
  27. trustgraph-0.5.3/trustgraph/storage/graph_embeddings/milvus/__main__.py +7 -0
  28. trustgraph-0.5.3/trustgraph/storage/triples/__init__.py +0 -0
  29. trustgraph-0.5.3/trustgraph/storage/triples/cassandra/__main__.py +7 -0
  30. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph.egg-info/PKG-INFO +11 -8
  31. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph.egg-info/SOURCES.txt +17 -0
  32. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph.egg-info/requires.txt +1 -0
  33. {trustgraph-0.5.1 → trustgraph-0.5.3}/LICENSE +0 -0
  34. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/chunker-recursive +0 -0
  35. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/embeddings-hf +0 -0
  36. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/embeddings-ollama +0 -0
  37. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/embeddings-vectorize +0 -0
  38. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/ge-write-milvus +0 -0
  39. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/graph-rag +0 -0
  40. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/graph-show +0 -0
  41. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/graph-to-turtle +0 -0
  42. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/init-pulsar-manager +0 -0
  43. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/kg-extract-definitions +0 -0
  44. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/kg-extract-relationships +0 -0
  45. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/pdf-decoder +0 -0
  46. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/query +0 -0
  47. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/run-processing +0 -0
  48. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/text-completion-azure +0 -0
  49. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/text-completion-claude +0 -0
  50. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/text-completion-ollama +0 -0
  51. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/text-completion-vertexai +0 -0
  52. {trustgraph-0.5.1 → trustgraph-0.5.3}/scripts/triples-write-cassandra +0 -0
  53. {trustgraph-0.5.1 → trustgraph-0.5.3}/setup.cfg +0 -0
  54. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/__init__.py +0 -0
  55. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/base/__init__.py +0 -0
  56. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/base/consumer.py +0 -0
  57. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/base/consumer_producer.py +0 -0
  58. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/base/producer.py +0 -0
  59. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/chunking/__init__.py +0 -0
  60. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/chunking/recursive/__init__.py +0 -0
  61. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/chunking/recursive/__main__.py +0 -0
  62. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/chunking/recursive/chunker.py +0 -0
  63. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/decoding/__init__.py +0 -0
  64. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/decoding/pdf/__init__.py +0 -0
  65. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/decoding/pdf/__main__.py +0 -0
  66. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/decoding/pdf/pdf_decoder.py +0 -0
  67. {trustgraph-0.5.1/trustgraph/embeddings → trustgraph-0.5.3/trustgraph/dump}/__init__.py +0 -0
  68. {trustgraph-0.5.1/trustgraph/kg → trustgraph-0.5.3/trustgraph/dump/graph_embeddings}/__init__.py +0 -0
  69. {trustgraph-0.5.1/trustgraph/embeddings/ollama → trustgraph-0.5.3/trustgraph/dump/graph_embeddings/parquet}/__init__.py +0 -0
  70. {trustgraph-0.5.1/trustgraph/storage/graph_embeddings/milvus → trustgraph-0.5.3/trustgraph/dump/graph_embeddings/parquet}/__main__.py +0 -0
  71. {trustgraph-0.5.1/trustgraph/model → trustgraph-0.5.3/trustgraph/dump/triples}/__init__.py +0 -0
  72. {trustgraph-0.5.1/trustgraph/storage/triples/cassandra → trustgraph-0.5.3/trustgraph/dump/triples/parquet}/__main__.py +0 -0
  73. {trustgraph-0.5.1/trustgraph/model/text_completion → trustgraph-0.5.3/trustgraph/embeddings}/__init__.py +0 -0
  74. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/embeddings/hf/__init__.py +0 -0
  75. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/embeddings/hf/__main__.py +0 -0
  76. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/embeddings/hf/hf.py +0 -0
  77. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/embeddings/ollama/__main__.py +0 -0
  78. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/embeddings/ollama/processor.py +0 -0
  79. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/embeddings/vectorize/__init__.py +0 -0
  80. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/embeddings/vectorize/__main__.py +0 -0
  81. {trustgraph-0.5.1/trustgraph/retrieval → trustgraph-0.5.3/trustgraph/kg}/__init__.py +0 -0
  82. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/kg/extract_definitions/__init__.py +0 -0
  83. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/kg/extract_definitions/__main__.py +0 -0
  84. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/kg/extract_relationships/__init__.py +0 -0
  85. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/kg/extract_relationships/__main__.py +0 -0
  86. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/log_level.py +0 -0
  87. {trustgraph-0.5.1/trustgraph/storage → trustgraph-0.5.3/trustgraph/model}/__init__.py +0 -0
  88. {trustgraph-0.5.1/trustgraph/storage/graph_embeddings → trustgraph-0.5.3/trustgraph/model/text_completion}/__init__.py +0 -0
  89. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/azure/__init__.py +0 -0
  90. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/azure/__main__.py +0 -0
  91. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/azure/llm.py +0 -0
  92. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/claude/__init__.py +0 -0
  93. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/claude/__main__.py +0 -0
  94. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/claude/llm.py +0 -0
  95. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/ollama/__init__.py +0 -0
  96. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/ollama/__main__.py +0 -0
  97. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/ollama/llm.py +0 -0
  98. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/vertexai/__init__.py +0 -0
  99. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/vertexai/__main__.py +0 -0
  100. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/model/text_completion/vertexai/llm.py +0 -0
  101. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/processing/__init__.py +0 -0
  102. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/processing/__main__.py +0 -0
  103. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/processing/processing.py +0 -0
  104. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/prompts.py +0 -0
  105. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/rdf.py +0 -0
  106. {trustgraph-0.5.1/trustgraph/storage/triples → trustgraph-0.5.3/trustgraph/retrieval}/__init__.py +0 -0
  107. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/retrieval/graph_rag/__init__.py +0 -0
  108. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/retrieval/graph_rag/__main__.py +0 -0
  109. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/retrieval/graph_rag/rag.py +0 -0
  110. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/schema.py +0 -0
  111. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/storage/graph_embeddings/milvus/__init__.py +0 -0
  112. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/storage/graph_embeddings/milvus/write.py +0 -0
  113. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/storage/triples/cassandra/__init__.py +0 -0
  114. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/storage/triples/cassandra/write.py +0 -0
  115. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/triple_vectors.py +0 -0
  116. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph/trustgraph.py +0 -0
  117. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph.egg-info/dependency_links.txt +0 -0
  118. {trustgraph-0.5.1 → trustgraph-0.5.3}/trustgraph.egg-info/top_level.txt +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trustgraph
3
- Version: 0.5.1
3
+ Version: 0.5.3
4
4
  Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
5
5
  Home-page: https://github.com/trustgraph-ai/trustgraph
6
- Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.5.1.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.5.3.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -32,6 +32,7 @@ Requires-Dist: anthropic
32
32
  Requires-Dist: google-cloud-aiplatform
33
33
  Requires-Dist: pyyaml
34
34
  Requires-Dist: prometheus-client
35
+ Requires-Dist: pyarrow
35
36
 
36
37
 
37
38
  # TrustGraph
@@ -95,11 +96,13 @@ package installed can also run the entire architecture.
95
96
  chunking algorithm to produce smaller text chunks.
96
97
  - `embeddings-hf` - A service which analyses text and returns a vector
97
98
  embedding using one of the HuggingFace embeddings models.
99
+ - `embeddings-ollama` - A service which analyses text and returns a vector
100
+ embedding using an Ollama embeddings model.
98
101
  - `embeddings-vectorize` - Uses an embeddings service to get a vector
99
102
  embedding which is added to the processor payload.
100
103
  - `graph-rag` - A query service which applies a Graph RAG algorithm to
101
104
  provide a response to a text prompt.
102
- - `graph-write-cassandra` - Takes knowledge graph edges and writes them to
105
+ - `triples-write-cassandra` - Takes knowledge graph edges and writes them to
103
106
  a Cassandra store.
104
107
  - `kg-extract-definitions` - knowledge extractor - examines text and
105
108
  produces graph edges.
@@ -115,15 +118,15 @@ package installed can also run the entire architecture.
115
118
  format. For instance, the wrapping of text between lines in a PDF document
116
119
  is not semantically encoded, so the decoder will see wrapped lines as
117
120
  space-separated.
118
- - `vector-write-milvus` - Takes vector-entity mappings and records them
121
+ - `ge-write-milvus` - Takes graph embeddings mappings and records them
119
122
  in the vector embeddings store.
120
123
 
121
124
  ## LM Specific Modules
122
125
 
123
- - `llm-azure-text` - Sends request to AzureAI serverless endpoint
124
- - `llm-claude-text` - Sends request to Anthropic's API
125
- - `llm-ollama-text` - Sends request to LM running using Ollama
126
- - `llm-vertexai-text` - Sends request to model available through VertexAI API
126
+ - `text-completion-azure` - Sends request to AzureAI serverless endpoint
127
+ - `text-completion-claude` - Sends request to Anthropic's API
128
+ - `text-completion-ollama` - Sends request to LM running using Ollama
129
+ - `text-completion-vertexai` - Sends request to model available through VertexAI API
127
130
 
128
131
  ## Quickstart Guide
129
132
 
@@ -60,11 +60,13 @@ package installed can also run the entire architecture.
60
60
  chunking algorithm to produce smaller text chunks.
61
61
  - `embeddings-hf` - A service which analyses text and returns a vector
62
62
  embedding using one of the HuggingFace embeddings models.
63
+ - `embeddings-ollama` - A service which analyses text and returns a vector
64
+ embedding using an Ollama embeddings model.
63
65
  - `embeddings-vectorize` - Uses an embeddings service to get a vector
64
66
  embedding which is added to the processor payload.
65
67
  - `graph-rag` - A query service which applies a Graph RAG algorithm to
66
68
  provide a response to a text prompt.
67
- - `graph-write-cassandra` - Takes knowledge graph edges and writes them to
69
+ - `triples-write-cassandra` - Takes knowledge graph edges and writes them to
68
70
  a Cassandra store.
69
71
  - `kg-extract-definitions` - knowledge extractor - examines text and
70
72
  produces graph edges.
@@ -80,15 +82,15 @@ package installed can also run the entire architecture.
80
82
  format. For instance, the wrapping of text between lines in a PDF document
81
83
  is not semantically encoded, so the decoder will see wrapped lines as
82
84
  space-separated.
83
- - `vector-write-milvus` - Takes vector-entity mappings and records them
85
+ - `ge-write-milvus` - Takes graph embeddings mappings and records them
84
86
  in the vector embeddings store.
85
87
 
86
88
  ## LM Specific Modules
87
89
 
88
- - `llm-azure-text` - Sends request to AzureAI serverless endpoint
89
- - `llm-claude-text` - Sends request to Anthropic's API
90
- - `llm-ollama-text` - Sends request to LM running using Ollama
91
- - `llm-vertexai-text` - Sends request to model available through VertexAI API
90
+ - `text-completion-azure` - Sends request to AzureAI serverless endpoint
91
+ - `text-completion-claude` - Sends request to Anthropic's API
92
+ - `text-completion-ollama` - Sends request to LM running using Ollama
93
+ - `text-completion-vertexai` - Sends request to model available through VertexAI API
92
94
 
93
95
  ## Quickstart Guide
94
96
 
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Concatenates multiple parquet files into a single parquet output
5
+ """
6
+
7
+ import pyarrow as pa
8
+ import pyarrow.parquet as pq
9
+ import pandas as pd
10
+ import sys
11
+ import argparse
12
+
13
+ parser = argparse.ArgumentParser(
14
+ prog="combine-parquet",
15
+ description=__doc__
16
+ )
17
+
18
+ parser.add_argument(
19
+ '-i', '--input',
20
+ nargs='*',
21
+ help=f'Input files'
22
+ )
23
+
24
+ parser.add_argument(
25
+ '-o', '--output',
26
+ help=f'Output files'
27
+ )
28
+
29
+ args = parser.parse_args()
30
+
31
+ df = None
32
+
33
+ for file in args.input:
34
+
35
+ part = pq.read_table(file).to_pandas()
36
+
37
+ if df is None:
38
+ df = part
39
+ else:
40
+ df = pd.concat([df, part], ignore_index=True)
41
+
42
+ if df is not None:
43
+
44
+ table = pa.Table.from_pandas(df)
45
+ pq.write_table(table, args.output)
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import pyarrow as pa
4
+ import pyarrow.csv as pc
5
+ import pyarrow.parquet as pq
6
+ import pandas as pd
7
+ import sys
8
+
9
+ df = None
10
+
11
+ for file in sys.argv[1:]:
12
+
13
+ part = pq.read_table(file).to_pandas()
14
+
15
+ if df is None:
16
+ df = part
17
+ else:
18
+ df = pd.concat([df, part], ignore_index=True)
19
+
20
+ if df is not None:
21
+
22
+ table = pa.Table.from_pandas(df)
23
+ pc.write_csv(table, sys.stdout.buffer)
24
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from trustgraph.dump.graph_embeddings.parquet import run
4
+
5
+ run()
6
+
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Loads Graph embeddings into TrustGraph processing.
5
+ """
6
+
7
+ import pulsar
8
+ from pulsar.schema import JsonSchema
9
+ from trustgraph.schema import GraphEmbeddings, Value
10
+ from trustgraph.schema import graph_embeddings_store_queue
11
+ import argparse
12
+ import os
13
+ import time
14
+ import pyarrow as pa
15
+ import pyarrow.parquet as pq
16
+
17
+ from trustgraph.log_level import LogLevel
18
+
19
+ class Loader:
20
+
21
+ def __init__(
22
+ self,
23
+ pulsar_host,
24
+ output_queue,
25
+ log_level,
26
+ file,
27
+ ):
28
+
29
+ self.client = pulsar.Client(
30
+ pulsar_host,
31
+ logger=pulsar.ConsoleLogger(log_level.to_pulsar())
32
+ )
33
+
34
+ self.producer = self.client.create_producer(
35
+ topic=output_queue,
36
+ schema=JsonSchema(GraphEmbeddings),
37
+ chunking_enabled=True,
38
+ )
39
+
40
+ self.file = file
41
+
42
+ def run(self):
43
+
44
+ try:
45
+
46
+ path = self.file
47
+
48
+ print("Reading file...")
49
+ table = pq.read_table(path)
50
+ print("Loaded.")
51
+
52
+ names = set(table.column_names)
53
+
54
+ if "embeddings" not in names:
55
+ print("No 'embeddings' column")
56
+
57
+ if "entity" not in names:
58
+ print("No 'entity' column")
59
+
60
+ embc = table.column("embeddings")
61
+ entc = table.column("entity")
62
+
63
+ for emb, ent in zip(embc, entc):
64
+
65
+ b = emb.as_py()
66
+ n = ent.as_py()
67
+
68
+ r = GraphEmbeddings(
69
+ vectors=b,
70
+ entity=Value(
71
+ value=n,
72
+ is_uri=n.startswith("https:")
73
+ )
74
+ )
75
+
76
+ self.producer.send(r)
77
+
78
+ except Exception as e:
79
+ print(e, flush=True)
80
+
81
+ def __del__(self):
82
+ self.client.close()
83
+
84
+ def main():
85
+
86
+ parser = argparse.ArgumentParser(
87
+ prog='loader',
88
+ description=__doc__,
89
+ )
90
+
91
+ default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
92
+ default_output_queue = graph_embeddings_store_queue
93
+
94
+ parser.add_argument(
95
+ '-p', '--pulsar-host',
96
+ default=default_pulsar_host,
97
+ help=f'Pulsar host (default: {default_pulsar_host})',
98
+ )
99
+
100
+ parser.add_argument(
101
+ '-o', '--output-queue',
102
+ default=default_output_queue,
103
+ help=f'Output queue (default: {default_output_queue})'
104
+ )
105
+
106
+ parser.add_argument(
107
+ '-l', '--log-level',
108
+ type=LogLevel,
109
+ default=LogLevel.ERROR,
110
+ choices=list(LogLevel),
111
+ help=f'Output queue (default: info)'
112
+ )
113
+
114
+ parser.add_argument(
115
+ '-f', '--file',
116
+ required=True,
117
+ help=f'File to load'
118
+ )
119
+
120
+ args = parser.parse_args()
121
+
122
+ while True:
123
+
124
+ try:
125
+ p = Loader(
126
+ pulsar_host=args.pulsar_host,
127
+ output_queue=args.output_queue,
128
+ log_level=args.log_level,
129
+ file=args.file,
130
+ )
131
+
132
+ p.run()
133
+
134
+ print("File loaded.")
135
+ break
136
+
137
+ except Exception as e:
138
+
139
+ print("Exception:", e, flush=True)
140
+ print("Will retry...", flush=True)
141
+
142
+ time.sleep(10)
143
+
144
+ main()
145
+
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Loads Graph embeddings into TrustGraph processing.
5
+ """
6
+
7
+ import pulsar
8
+ from pulsar.schema import JsonSchema
9
+ from trustgraph.schema import Triple, Value
10
+ from trustgraph.schema import triples_store_queue
11
+ import argparse
12
+ import os
13
+ import time
14
+ import pyarrow as pa
15
+ import pyarrow.parquet as pq
16
+
17
+ from trustgraph.log_level import LogLevel
18
+
19
+ class Loader:
20
+
21
+ def __init__(
22
+ self,
23
+ pulsar_host,
24
+ output_queue,
25
+ log_level,
26
+ file,
27
+ ):
28
+
29
+ self.client = pulsar.Client(
30
+ pulsar_host,
31
+ logger=pulsar.ConsoleLogger(log_level.to_pulsar())
32
+ )
33
+
34
+ self.producer = self.client.create_producer(
35
+ topic=output_queue,
36
+ schema=JsonSchema(Triple),
37
+ chunking_enabled=True,
38
+ )
39
+
40
+ self.file = file
41
+
42
+ def run(self):
43
+
44
+ try:
45
+
46
+ path = self.file
47
+
48
+ print("Reading file...")
49
+ table = pq.read_table(path)
50
+ print("Loaded.")
51
+
52
+ names = set(table.column_names)
53
+
54
+ if "s" not in names:
55
+ print("No 's' column")
56
+
57
+ if "p" not in names:
58
+ print("No 'p' column")
59
+
60
+ if "o" not in names:
61
+ print("No 'o' column")
62
+
63
+ sc = table.column("s")
64
+ pc = table.column("p")
65
+ oc = table.column("o")
66
+
67
+ for s, p, o in zip(sc, pc, oc):
68
+
69
+ r = Triple(
70
+ s=Value(value=s.as_py(), is_uri=True),
71
+ p=Value(value=p.as_py(), is_uri=True),
72
+ o=Value(value=o.as_py(), is_uri=o.as_py().startswith("https:"))
73
+ )
74
+
75
+ self.producer.send(r)
76
+
77
+ except Exception as e:
78
+ print(e, flush=True)
79
+
80
+ def __del__(self):
81
+ self.client.close()
82
+
83
+ def main():
84
+
85
+ parser = argparse.ArgumentParser(
86
+ prog='loader',
87
+ description=__doc__,
88
+ )
89
+
90
+ default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
91
+ default_output_queue = triples_store_queue
92
+
93
+ parser.add_argument(
94
+ '-p', '--pulsar-host',
95
+ default=default_pulsar_host,
96
+ help=f'Pulsar host (default: {default_pulsar_host})',
97
+ )
98
+
99
+ parser.add_argument(
100
+ '-o', '--output-queue',
101
+ default=default_output_queue,
102
+ help=f'Output queue (default: {default_output_queue})'
103
+ )
104
+
105
+ parser.add_argument(
106
+ '-l', '--log-level',
107
+ type=LogLevel,
108
+ default=LogLevel.ERROR,
109
+ choices=list(LogLevel),
110
+ help=f'Output queue (default: info)'
111
+ )
112
+
113
+ parser.add_argument(
114
+ '-f', '--file',
115
+ required=True,
116
+ help=f'File to load'
117
+ )
118
+
119
+ args = parser.parse_args()
120
+
121
+ while True:
122
+
123
+ try:
124
+ p = Loader(
125
+ pulsar_host=args.pulsar_host,
126
+ output_queue=args.output_queue,
127
+ log_level=args.log_level,
128
+ file=args.file,
129
+ )
130
+
131
+ p.run()
132
+
133
+ print("File loaded.")
134
+ break
135
+
136
+ except Exception as e:
137
+
138
+ print("Exception:", e, flush=True)
139
+ print("Will retry...", flush=True)
140
+
141
+ time.sleep(10)
142
+
143
+ main()
144
+
@@ -6,7 +6,7 @@ Loads a PDF documented into TrustGraph processing.
6
6
 
7
7
  import pulsar
8
8
  from pulsar.schema import JsonSchema
9
- from trustgraph.schema import Document, Source
9
+ from trustgraph.schema import Document, Source, document_ingest_queue
10
10
  import base64
11
11
  import hashlib
12
12
  import argparse
@@ -72,7 +72,7 @@ def main():
72
72
  )
73
73
 
74
74
  default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
75
- default_output_queue = 'document-load'
75
+ default_output_queue = document_ingest_queue
76
76
 
77
77
  parser.add_argument(
78
78
  '-p', '--pulsar-host',
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from trustgraph.dump.triples.parquet import run
4
+
5
+ run()
6
+
@@ -4,7 +4,7 @@ import os
4
4
  with open("README.md", "r") as fh:
5
5
  long_description = fh.read()
6
6
 
7
- version = "0.5.1"
7
+ version = "0.5.3"
8
8
 
9
9
  setuptools.setup(
10
10
  name="trustgraph",
@@ -44,12 +44,16 @@ setuptools.setup(
44
44
  "google-cloud-aiplatform",
45
45
  "pyyaml",
46
46
  "prometheus-client",
47
+ "pyarrow",
47
48
  ],
48
49
  scripts=[
49
50
  "scripts/chunker-recursive",
51
+ "scripts/concat-parquet",
52
+ "scripts/dump-parquet",
50
53
  "scripts/embeddings-hf",
51
54
  "scripts/embeddings-ollama",
52
55
  "scripts/embeddings-vectorize",
56
+ "scripts/ge-dump-parquet",
53
57
  "scripts/ge-write-milvus",
54
58
  "scripts/graph-rag",
55
59
  "scripts/graph-show",
@@ -57,6 +61,8 @@ setuptools.setup(
57
61
  "scripts/init-pulsar-manager",
58
62
  "scripts/kg-extract-definitions",
59
63
  "scripts/kg-extract-relationships",
64
+ "scripts/load-graph-embeddings",
65
+ "scripts/load-triples",
60
66
  "scripts/loader",
61
67
  "scripts/pdf-decoder",
62
68
  "scripts/query",
@@ -65,6 +71,7 @@ setuptools.setup(
65
71
  "scripts/text-completion-claude",
66
72
  "scripts/text-completion-ollama",
67
73
  "scripts/text-completion-vertexai",
74
+ "scripts/triples-dump-parquet",
68
75
  "scripts/triples-write-cassandra",
69
76
  ]
70
77
  )
@@ -79,20 +79,20 @@ class BaseProcessor:
79
79
  @classmethod
80
80
  def start(cls, prog, doc):
81
81
 
82
- while True:
82
+ parser = argparse.ArgumentParser(
83
+ prog=prog,
84
+ description=doc
85
+ )
83
86
 
84
- parser = argparse.ArgumentParser(
85
- prog=prog,
86
- description=doc
87
- )
87
+ cls.add_args(parser)
88
88
 
89
- cls.add_args(parser)
89
+ args = parser.parse_args()
90
+ args = vars(args)
90
91
 
91
- args = parser.parse_args()
92
- args = vars(args)
92
+ if args["metrics_enabled"]:
93
+ start_http_server(args["metrics_port"])
93
94
 
94
- if args["metrics_enabled"]:
95
- start_http_server(args["metrics_port"])
95
+ while True:
96
96
 
97
97
  try:
98
98
 
@@ -0,0 +1,87 @@
1
+
2
+ """
3
+ Write graph embeddings to parquet files in a directory.
4
+ """
5
+
6
+ import pulsar
7
+ import base64
8
+ import os
9
+ import argparse
10
+ import time
11
+
12
+ from .... trustgraph import TrustGraph
13
+ from .... schema import GraphEmbeddings
14
+ from .... schema import graph_embeddings_store_queue
15
+ from .... log_level import LogLevel
16
+ from .... base import Consumer
17
+
18
+ from . writer import ParquetWriter
19
+
20
+ module = ".".join(__name__.split(".")[1:-1])
21
+
22
+ default_input_queue = graph_embeddings_store_queue
23
+ default_subscriber = module
24
+ default_graph_host='localhost'
25
+ default_directory = "."
26
+ default_file_template = "graph-embeds-{id}.parquet"
27
+ default_rotation_time = 60
28
+
29
+ class Processor(Consumer):
30
+
31
+ def __init__(self, **params):
32
+
33
+ input_queue = params.get("input_queue", default_input_queue)
34
+ subscriber = params.get("subscriber", default_subscriber)
35
+ directory = params.get("directory", default_directory)
36
+ file_template = params.get("file_template", default_file_template)
37
+ rotation_time = params.get("rotation_time", default_rotation_time)
38
+
39
+ super(Processor, self).__init__(
40
+ **params | {
41
+ "input_queue": input_queue,
42
+ "subscriber": subscriber,
43
+ "input_schema": GraphEmbeddings,
44
+ }
45
+ )
46
+
47
+ self.writer = ParquetWriter(directory, file_template, rotation_time)
48
+
49
+ def __del__(self):
50
+ if hasattr(self, "writer"):
51
+ del self.writer
52
+
53
+ def handle(self, msg):
54
+
55
+ v = msg.value()
56
+ self.writer.write(v.vectors, v.entity.value)
57
+
58
+ @staticmethod
59
+ def add_args(parser):
60
+
61
+ Consumer.add_args(
62
+ parser, default_input_queue, default_subscriber,
63
+ )
64
+
65
+ parser.add_argument(
66
+ '-d', '--directory',
67
+ default=default_directory,
68
+ help=f'Directory to write to (default: {default_directory})'
69
+ )
70
+
71
+ parser.add_argument(
72
+ '-f', '--file-template',
73
+ default=default_file_template,
74
+ help=f'Directory to write to (default: {default_file_template})'
75
+ )
76
+
77
+ parser.add_argument(
78
+ '-t', '--rotation-time',
79
+ type=int,
80
+ default=default_rotation_time,
81
+ help=f'Rotation time / seconds (default: {default_rotation_time})'
82
+ )
83
+
84
+ def run():
85
+
86
+ Processor.start(module, __doc__)
87
+