├── tests ├── contract │ └── __init__.py ├── integration │ └── __init__.py ├── unit │ ├── test_chunking │ │ └── __init__.py │ ├── test_decoding │ │ └── __init__.py │ ├── test_config │ │ └── __init__.py │ ├── test_extract │ │ ├── __init__.py │ │ └── test_ontology │ │ │ └── __init__.py │ ├── test_cores │ │ └── __init__.py │ ├── __init__.py │ ├── test_cli │ │ ├── __init__.py │ │ └── conftest.py │ ├── test_text_completion │ │ ├── __init__.py │ │ └── common │ │ │ └── __init__.py │ ├── test_retrieval │ │ └── test_structured_diag │ │ │ └── __init__.py │ ├── test_embeddings │ │ └── __init__.py │ ├── test_knowledge_graph │ │ └── __init__.py │ └── test_agent │ │ └── __init__.py ├── __init__.py ├── requirements.txt ├── pytest.ini └── utils │ └── __init__.py ├── trustgraph-flow ├── trustgraph │ ├── __init__.py │ ├── agent │ │ ├── __init__.py │ │ ├── react │ │ │ ├── __init__.py │ │ │ ├── __main__.py │ │ │ ├── types.py │ │ │ └── README.md │ │ └── mcp_tool │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── chunking │ │ ├── __init__.py │ │ ├── token │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ └── recursive │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── decoding │ │ ├── __init__.py │ │ ├── pdf │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ └── mistral_ocr │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── direct │ │ └── __init__.py │ ├── external │ │ ├── __init__.py │ │ └── wikipedia │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── extract │ │ ├── __init__.py │ │ └── kg │ │ │ ├── __init__.py │ │ │ ├── agent │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── ontology │ │ │ ├── __init__.py │ │ │ └── run.py │ │ │ ├── objects │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── topics │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── definitions │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ └── relationships │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── model │ │ ├── __init__.py │ │ └── text_completion │ │ │ ├── __init__.py │ │ │ ├── tgi │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── azure │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── claude │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── cohere │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── lmstudio │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── mistral │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── ollama │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── openai │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── vllm │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── azure_openai │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── llamafile │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ └── googleaistudio │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── prompt │ │ ├── __init__.py │ │ └── template │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── query │ │ ├── __init__.py │ │ ├── objects │ │ │ ├── __init__.py │ │ │ └── cassandra │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ ├── triples │ │ │ ├── __init__.py │ │ │ ├── neo4j │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ ├── cassandra │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ ├── falkordb │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ └── memgraph │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ ├── doc_embeddings │ │ │ ├── __init__.py │ │ │ ├── milvus │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ ├── pinecone │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ └── qdrant │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ └── graph_embeddings │ │ │ ├── __init__.py │ │ │ ├── milvus │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ ├── pinecone │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ │ └── qdrant │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── retrieval │ │ ├── __init__.py │ │ ├── nlp_query │ │ │ ├── __init__.py │ │ │ ├── __main__.py │ │ │ └── pass1.txt │ │ ├── structured_query │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ ├── graph_rag │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ ├── document_rag │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ └── structured_diag │ │ │ └── __init__.py │ ├── storage │ │ ├── __init__.py │ │ ├── rows │ │ │ ├── __init__.py │ │ │ └── cassandra │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ ├── triples │ │ │ ├── __init__.py │ │ │ ├── neo4j │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ ├── cassandra │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ ├── falkordb │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ └── memgraph │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ ├── doc_embeddings │ │ │ ├── __init__.py │ │ │ ├── milvus │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ ├── pinecone │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ └── qdrant │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ ├── graph_embeddings │ │ │ ├── __init__.py │ │ │ ├── milvus │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ ├── pinecone │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ │ └── qdrant │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ ├── object_embeddings │ │ │ └── __init__.py │ │ ├── objects │ │ │ ├── __init__.py │ │ │ └── cassandra │ │ │ │ ├── __init__.py │ │ │ │ └── __main__.py │ │ └── knowledge │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── tables │ │ └── __init__.py │ ├── embeddings │ │ ├── __init__.py │ │ ├── ollama │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ ├── fastembed │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ ├── graph_embeddings │ │ │ ├── __init__.py │ │ │ └── __main__.py │ │ └── document_embeddings │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── rev_gateway │ │ ├── __init__.py │ │ └── __main__.py │ ├── cores │ │ ├── __init__.py │ │ └── __main__.py │ ├── gateway │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── running.py │ │ ├── auth.py │ │ ├── dispatch │ │ │ ├── document_load.py │ │ │ ├── text_load.py │ │ │ ├── agent.py │ │ │ ├── mcp_tool.py │ │ │ ├── flow.py │ │ │ ├── graph_rag.py │ │ │ ├── prompt.py │ │ │ ├── embeddings.py │ │ │ ├── objects_query.py │ │ │ ├── document_rag.py │ │ │ ├── config.py │ │ │ ├── structured_query.py │ │ │ ├── triples_query.py │ │ │ ├── nlp_query.py │ │ │ ├── text_completion.py │ │ │ ├── structured_diag.py │ │ │ ├── graph_embeddings_query.py │ │ │ ├── sender.py │ │ │ ├── knowledge.py │ │ │ └── collection_management.py │ │ └── unused │ │ │ ├── dbpedia.py │ │ │ ├── internet_search.py │ │ │ └── encyclopedia.py │ ├── librarian │ │ ├── __init__.py │ │ └── __main__.py │ ├── metering │ │ ├── __init__.py │ │ └── __main__.py │ ├── config │ │ └── service │ │ │ ├── __init__.py │ │ │ └── __main__.py │ ├── processing │ │ ├── __init__.py │ │ └── __main__.py │ └── template │ │ └── __init__.py └── README.md ├── trustgraph-base ├── trustgraph │ ├── clients │ │ ├── __init__.py │ │ ├── embeddings_client.py │ │ ├── document_rag_client.py │ │ └── graph_rag_client.py │ ├── objects │ │ ├── __init__.py │ │ └── object.py │ ├── api │ │ ├── __init__.py │ │ ├── exceptions.py │ │ └── types.py │ ├── base │ │ ├── spec.py │ │ ├── parameter_spec.py │ │ ├── producer_spec.py │ │ ├── flow.py │ │ ├── subscriber_spec.py │ │ ├── embeddings_client.py │ │ ├── graph_rag_client.py │ │ ├── tool_client.py │ │ ├── agent_client.py │ │ ├── consumer_spec.py │ │ ├── triples_store_service.py │ │ ├── structured_query_client.py │ │ ├── graph_embeddings_store_service.py │ │ ├── document_embeddings_store_service.py │ │ └── document_embeddings_client.py │ ├── schema │ │ ├── core │ │ │ ├── __init__.py │ │ │ ├── topic.py │ │ │ ├── metadata.py │ │ │ └── primitives.py │ │ ├── __init__.py │ │ ├── knowledge │ │ │ ├── __init__.py │ │ │ ├── rows.py │ │ │ ├── nlp.py │ │ │ ├── structured.py │ │ │ ├── object.py │ │ │ ├── document.py │ │ │ └── graph.py │ │ ├── services │ │ │ ├── __init__.py │ │ │ ├── lookup.py │ │ │ ├── structured_query.py │ │ │ ├── nlp_query.py │ │ │ ├── prompt.py │ │ │ ├── retrieval.py │ │ │ ├── objects_query.py │ │ │ ├── llm.py │ │ │ ├── diagnosis.py │ │ │ ├── agent.py │ │ │ └── storage.py │ │ └── README.flows │ ├── knowledge │ │ ├── __init__.py │ │ ├── identifier.py │ │ ├── defs.py │ │ └── organization.py │ ├── exceptions.py │ ├── rdf.py │ ├── log_level.py │ └── messaging │ │ └── translators │ │ ├── embeddings.py │ │ └── base.py ├── README.md └── pyproject.toml ├── trustgraph-embeddings-hf ├── trustgraph │ ├── __init__.py │ └── embeddings │ │ ├── __init__.py │ │ └── hf │ │ ├── __init__.py │ │ └── __main__.py ├── README.md └── pyproject.toml ├── trustgraph ├── README.md └── pyproject.toml ├── docs └── apis │ └── api-document-load.md ├── tests.manual ├── test-config ├── test-get-config ├── test-flow-get-class ├── test-llm2 ├── test-llm3 ├── test-graph-rag2 ├── test-flow-stop-flow ├── test-prompt-french-question ├── test-flow-start-flow ├── test-prompt-analyze ├── test-prompt-spanish-question ├── test-embeddings ├── test-llm ├── test-doc-rag ├── test-lang-topics ├── test-prompt-question ├── query ├── test-doc-embeddings ├── test-graph-embeddings ├── test-lang-relationships ├── test-lang-definition ├── test-run-extract-row ├── test-graph-rag ├── test-doc-prompt ├── test-load-pdf ├── test-load-text ├── test-milvus └── test-agent ├── trustgraph-cli ├── README.md └── trustgraph │ └── cli │ ├── __init__.py │ ├── init_pulsar_manager.py │ ├── show_config.py │ ├── stop_flow.py │ ├── delete_flow_class.py │ ├── show_processor_state.py │ ├── get_flow_class.py │ ├── show_kg_cores.py │ ├── remove_library_document.py │ ├── delete_kg_core.py │ ├── put_flow_class.py │ ├── delete_config_item.py │ ├── list_config_items.py │ └── stop_library_processing.py ├── trustgraph-mcp ├── README.md ├── trustgraph │ └── mcp_server │ │ ├── __init__.py │ │ └── __main__.py └── pyproject.toml ├── trustgraph-ocr ├── README.md ├── trustgraph │ └── decoding │ │ └── ocr │ │ ├── __init__.py │ │ └── __main__.py └── pyproject.toml ├── trustgraph-bedrock ├── README.md ├── trustgraph │ └── model │ │ └── text_completion │ │ └── bedrock │ │ ├── __init__.py │ │ └── __main__.py └── pyproject.toml ├── trustgraph-vertexai ├── README.md ├── trustgraph │ └── model │ │ └── text_completion │ │ └── vertexai │ │ ├── __init__.py │ │ └── __main__.py └── pyproject.toml ├── requirements.txt ├── test-api ├── test-agent2-api ├── test-dbpedia ├── test-encyclopedia ├── test-internet-search ├── test-embeddings-api ├── test-agent-api ├── test-graph-rag-api ├── test-llm2-api ├── test-knowledge-list ├── test-library-list ├── test-library-list-documents ├── test-library-list-processing ├── test-triples-query-api ├── test-prompt-api ├── test-knowledge-delete ├── test-knowledge-fetch ├── test-prompt2-api ├── test-library-remove-processing ├── test-library-remove-document ├── test-library-remove-document2 ├── test-library-get-document-content ├── test-library-get-document-metadata ├── test-llm-api ├── test-library-add-processing ├── test-library-add-processing2 └── test-knowledge-fetch2 ├── .gitignore ├── install_packages.sh ├── .coveragerc ├── schema.ttl ├── run_tests.sh └── .github └── workflows └── pull-request.yaml /tests/contract/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/integration/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/unit/test_chunking/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/unit/test_decoding/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/clients/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/objects/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-embeddings-hf/trustgraph/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/agent/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/chunking/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/decoding/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/direct/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/external/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/prompt/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/tables/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/objects/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/triples/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/rows/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph/README.md: -------------------------------------------------------------------------------- 1 | See https://trustgraph.ai/ 2 | -------------------------------------------------------------------------------- /docs/apis/api-document-load.md: -------------------------------------------------------------------------------- 1 | 2 | Coming soon 3 | 4 | -------------------------------------------------------------------------------- /tests.manual/test-config: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | TrustGraph test suite 3 | """ -------------------------------------------------------------------------------- /trustgraph-base/README.md: -------------------------------------------------------------------------------- 1 | See https://trustgraph.ai/ 2 | -------------------------------------------------------------------------------- /trustgraph-cli/README.md: -------------------------------------------------------------------------------- 1 | See https://trustgraph.ai/ 2 | -------------------------------------------------------------------------------- /trustgraph-embeddings-hf/trustgraph/embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/README.md: -------------------------------------------------------------------------------- 1 | See https://trustgraph.ai/ 2 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/triples/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-mcp/README.md: -------------------------------------------------------------------------------- 1 | See https://trustgraph.ai/ 2 | -------------------------------------------------------------------------------- /trustgraph-ocr/README.md: -------------------------------------------------------------------------------- 1 | See https://trustgraph.ai/ 2 | -------------------------------------------------------------------------------- /tests/unit/test_config/__init__.py: -------------------------------------------------------------------------------- 1 | # Configuration service tests -------------------------------------------------------------------------------- /tests/unit/test_extract/__init__.py: -------------------------------------------------------------------------------- 1 | # Extraction processor tests -------------------------------------------------------------------------------- /trustgraph-bedrock/README.md: -------------------------------------------------------------------------------- 1 | See https://trustgraph.ai/ 2 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/doc_embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/graph_embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/doc_embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/graph_embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /trustgraph-vertexai/README.md: -------------------------------------------------------------------------------- 1 | See https://trustgraph.ai/ 2 | -------------------------------------------------------------------------------- /tests/unit/test_cores/__init__.py: -------------------------------------------------------------------------------- 1 | # Test package for cores module -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/__init__.py: -------------------------------------------------------------------------------- 1 | # TrustGraph CLI modules -------------------------------------------------------------------------------- /trustgraph-embeddings-hf/README.md: -------------------------------------------------------------------------------- 1 | See https://trustgraph.ai/ 2 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/object_embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for TrustGraph services 3 | """ -------------------------------------------------------------------------------- /tests/unit/test_cli/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for CLI modules. 3 | """ -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/api/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . api import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/spec.py: -------------------------------------------------------------------------------- 1 | 2 | class Spec: 3 | pass 4 | 5 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/agent/__init__.py: -------------------------------------------------------------------------------- 1 | from .extract import * -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/objects/__init__.py: -------------------------------------------------------------------------------- 1 | # Objects storage module -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/ontology/__init__.py: -------------------------------------------------------------------------------- 1 | from . extract import * -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/nlp_query/__init__.py: -------------------------------------------------------------------------------- 1 | from . service import * -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/rev_gateway/__init__.py: -------------------------------------------------------------------------------- 1 | from . service import run 2 | -------------------------------------------------------------------------------- /trustgraph-mcp/trustgraph/mcp_server/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . mcp import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/agent/react/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/cores/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import run 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/librarian/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/metering/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . counter import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/structured_query/__init__.py: -------------------------------------------------------------------------------- 1 | from . service import * -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/agent/mcp_tool/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/chunking/token/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . chunker import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/config/service/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/decoding/pdf/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . pdf_decoder import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/processing/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . processing import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/prompt/template/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/graph_rag/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . rag import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/objects/cassandra/__init__.py: -------------------------------------------------------------------------------- 1 | from . write import * 2 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/template/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from .prompt_manager import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-ocr/trustgraph/decoding/ocr/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . pdf_decoder import * 3 | 4 | -------------------------------------------------------------------------------- /tests/unit/test_extract/test_ontology/__init__.py: -------------------------------------------------------------------------------- 1 | """Tests for ontology-based extraction.""" 2 | -------------------------------------------------------------------------------- /tests/unit/test_text_completion/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for text completion services 3 | """ -------------------------------------------------------------------------------- /trustgraph-embeddings-hf/trustgraph/embeddings/hf/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . hf import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/chunking/recursive/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . chunker import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/embeddings/ollama/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . processor import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/external/wikipedia/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/objects/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . processor import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/topics/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . extract import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/tgi/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/objects/cassandra/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/triples/neo4j/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/document_rag/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . rag import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/knowledge/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . store import run 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/rows/cassandra/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/triples/neo4j/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/decoding/mistral_ocr/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . processor import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/embeddings/fastembed/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . processor import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/definitions/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . extract import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/relationships/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . extract import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/azure/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/claude/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/cohere/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/lmstudio/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/mistral/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/ollama/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/openai/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/vllm/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/triples/cassandra/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/triples/falkordb/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/triples/memgraph/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/objects/cassandra/__main__.py: -------------------------------------------------------------------------------- 1 | from . write import run 2 | 3 | run() -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/triples/cassandra/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/triples/falkordb/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/triples/memgraph/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /tests/unit/test_text_completion/common/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Common utilities for text completion tests 3 | """ -------------------------------------------------------------------------------- /trustgraph-bedrock/trustgraph/model/text_completion/bedrock/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/embeddings/graph_embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . embeddings import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/azure_openai/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/llamafile/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/doc_embeddings/milvus/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/doc_embeddings/pinecone/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/doc_embeddings/qdrant/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/graph_embeddings/milvus/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/graph_embeddings/pinecone/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/graph_embeddings/qdrant/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/doc_embeddings/milvus/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/doc_embeddings/pinecone/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/doc_embeddings/qdrant/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/graph_embeddings/milvus/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/graph_embeddings/pinecone/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/graph_embeddings/qdrant/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . write import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-vertexai/trustgraph/model/text_completion/vertexai/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/embeddings/document_embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . embeddings import * 3 | 4 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/googleaistudio/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . llm import * 3 | 4 | -------------------------------------------------------------------------------- /tests/unit/test_retrieval/test_structured_diag/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit and contract tests for structured-diag service 3 | """ -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/core/__init__.py: -------------------------------------------------------------------------------- 1 | from .primitives import * 2 | from .metadata import * 3 | from .topic import * -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/structured_diag/__init__.py: -------------------------------------------------------------------------------- 1 | # Structured data diagnosis service 2 | from .service import * -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/cores/__main__.py: -------------------------------------------------------------------------------- 1 | 2 | from . service import run 3 | 4 | if __name__ == '__main__': 5 | run() 6 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/nlp_query/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | run() -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/structured_query/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | run() -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/knowledge/__main__.py: -------------------------------------------------------------------------------- 1 | 2 | from . store import run 3 | 4 | if __name__ == '__main__': 5 | run() 6 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/agent/__main__.py: -------------------------------------------------------------------------------- 1 | from .extract import Processor 2 | 3 | if __name__ == "__main__": 4 | Processor.run() -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/objects/cassandra/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | run() 6 | 7 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/api/exceptions.py: -------------------------------------------------------------------------------- 1 | 2 | class ProtocolException(Exception): 3 | pass 4 | 5 | class ApplicationException(Exception): 6 | pass 7 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/embeddings/document_embeddings/__main__.py: -------------------------------------------------------------------------------- 1 | 2 | from . embeddings import run 3 | 4 | if __name__ == '__main__': 5 | run() 6 | 7 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/embeddings/graph_embeddings/__main__.py: -------------------------------------------------------------------------------- 1 | 2 | from . embeddings import run 3 | 4 | if __name__ == '__main__': 5 | run() 6 | 7 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-mcp/trustgraph/mcp_server/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . mcp import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/agent/react/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/librarian/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/metering/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . counter import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-embeddings-hf/trustgraph/embeddings/hf/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/agent/mcp_tool/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/chunking/token/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . chunker import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/config/service/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/decoding/pdf/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . pdf_decoder import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/topics/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . extract import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/processing/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . processing import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/prompt/template/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/triples/falkordb/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/triples/memgraph/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/triples/neo4j/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/graph_rag/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . rag import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-ocr/trustgraph/decoding/ocr/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . pdf_decoder import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/chunking/recursive/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . chunker import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/decoding/mistral_ocr/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . processor import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/embeddings/fastembed/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . processor import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/embeddings/ollama/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . processor import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/external/wikipedia/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . service import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/definitions/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . extract import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/objects/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . processor import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/tgi/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/vllm/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/doc_embeddings/milvus/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/doc_embeddings/qdrant/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/triples/cassandra/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/document_rag/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . rag import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/rows/cassandra/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/triples/falkordb/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/triples/memgraph/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/triples/neo4j/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/relationships/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . extract import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/azure/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/claude/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/cohere/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/llamafile/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/lmstudio/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/mistral/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/ollama/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/openai/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/doc_embeddings/pinecone/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/graph_embeddings/milvus/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/graph_embeddings/pinecone/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/query/graph_embeddings/qdrant/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . hf import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/doc_embeddings/milvus/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/doc_embeddings/qdrant/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/triples/cassandra/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/core/topic.py: -------------------------------------------------------------------------------- 1 | 2 | def topic(topic, kind='persistent', tenant='tg', namespace='flow'): 3 | return f"{kind}://{tenant}/{namespace}/{topic}" 4 | 5 | -------------------------------------------------------------------------------- /trustgraph-bedrock/trustgraph/model/text_completion/bedrock/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/azure_openai/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/model/text_completion/googleaistudio/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/doc_embeddings/pinecone/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/graph_embeddings/milvus/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/graph_embeddings/pinecone/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/storage/graph_embeddings/qdrant/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . write import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-vertexai/trustgraph/model/text_completion/vertexai/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from . llm import run 4 | 5 | if __name__ == '__main__': 6 | run() 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/knowledge/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from . defs import * 3 | from . identifier import * 4 | from . publication import * 5 | from . document import * 6 | from . organization import * 7 | 8 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/running.py: -------------------------------------------------------------------------------- 1 | 2 | class Running: 3 | def __init__(self): self.running = True 4 | def get(self): return self.running 5 | def stop(self): self.running = False 6 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/extract/kg/ontology/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | OntoRAG extraction service launcher. 5 | """ 6 | 7 | from . extract import run 8 | 9 | if __name__ == "__main__": 10 | run() -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/objects/object.py: -------------------------------------------------------------------------------- 1 | 2 | class Schema: 3 | def __init__(self, name, description, fields): 4 | self.name = name 5 | self.description = description 6 | self.fields = fields 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/requirements.txt: -------------------------------------------------------------------------------- 1 | pytest>=7.0.0 2 | pytest-asyncio>=0.21.0 3 | pytest-mock>=3.10.0 4 | pytest-cov>=4.0.0 5 | google-cloud-aiplatform>=1.25.0 6 | google-auth>=2.17.0 7 | google-api-core>=2.11.0 8 | pulsar-client>=3.0.0 9 | prometheus-client>=0.16.0 -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | # Import core types and primitives 3 | from .core import * 4 | 5 | # Import knowledge schemas 6 | from .knowledge import * 7 | 8 | # Import service schemas 9 | from .services import * 10 | 11 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/exceptions.py: -------------------------------------------------------------------------------- 1 | 2 | class TooManyRequests(Exception): 3 | pass 4 | 5 | class LlmError(Exception): 6 | pass 7 | 8 | class ParseError(Exception): 9 | pass 10 | 11 | class RequestError(Exception): 12 | pass 13 | 14 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/knowledge/__init__.py: -------------------------------------------------------------------------------- 1 | from .graph import * 2 | from .document import * 3 | from .embeddings import * 4 | from .knowledge import * 5 | from .nlp import * 6 | from .rows import * 7 | from .structured import * 8 | from .object import * 9 | -------------------------------------------------------------------------------- /tests.manual/test-get-config: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.config_client import ConfigClient 5 | 6 | cli = ConfigClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | resp = cli.request_config() 9 | 10 | print(resp) 11 | 12 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/rev_gateway/__main__.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from .service import run 3 | 4 | logging.basicConfig( 5 | level=logging.INFO, 6 | format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' 7 | ) 8 | 9 | if __name__ == "__main__": 10 | run() 11 | 12 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/rdf.py: -------------------------------------------------------------------------------- 1 | 2 | RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" 3 | RDF_LABEL = "http://www.w3.org/2000/01/rdf-schema#label" 4 | DEFINITION = "http://www.w3.org/2004/02/skos/core#definition" 5 | SUBJECT_OF = "https://schema.org/subjectOf" 6 | 7 | TRUSTGRAPH_ENTITIES = "http://trustgraph.ai/e/" 8 | 9 | -------------------------------------------------------------------------------- /tests/unit/test_embeddings/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for embeddings services 3 | 4 | Testing Strategy: 5 | - Mock external embedding libraries (FastEmbed, Ollama client) 6 | - Test core business logic for text embedding generation 7 | - Test error handling and edge cases 8 | - Test vector dimension consistency 9 | - Test batch processing logic 10 | """ -------------------------------------------------------------------------------- /tests.manual/test-flow-get-class: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | 5 | url = "http://localhost:8088/" 6 | 7 | resp = requests.post( 8 | f"{url}/api/v1/flow", 9 | json={ 10 | "operation": "get-class", 11 | "class-name": "default", 12 | } 13 | ) 14 | 15 | resp = resp.json() 16 | 17 | print(resp["class-definition"]) 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests.manual/test-llm2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.llm_client import LlmClient 5 | 6 | llm = LlmClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | prompt="What is 2 + 12?" 9 | 10 | try: 11 | resp = llm.request(prompt) 12 | print(resp) 13 | except Exception as e: 14 | print(f"{e.__class__.__name__}: {e}") 15 | 16 | -------------------------------------------------------------------------------- /tests.manual/test-llm3: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.llm_client import LlmClient 5 | 6 | llm = LlmClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | prompt="What is 2 + 12?" 9 | 10 | try: 11 | resp = llm.request(prompt) 12 | print(resp) 13 | except Exception as e: 14 | print(f"{e.__class__.__name__}: {e}") 15 | 16 | -------------------------------------------------------------------------------- /tests.manual/test-graph-rag2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.graph_rag_client import GraphRagClient 5 | 6 | rag = GraphRagClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | query="""List 20 key points to describe the research that led to the discovery of Leo VI. 9 | """ 10 | 11 | resp = rag.request(query) 12 | 13 | print(resp) 14 | 15 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/core/metadata.py: -------------------------------------------------------------------------------- 1 | 2 | from pulsar.schema import Record, String, Array 3 | from .primitives import Triple 4 | 5 | class Metadata(Record): 6 | 7 | # Source identifier 8 | id = String() 9 | 10 | # Subgraph 11 | metadata = Array(Triple()) 12 | 13 | # Collection management 14 | user = String() 15 | collection = String() 16 | 17 | -------------------------------------------------------------------------------- /tests/unit/test_knowledge_graph/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for knowledge graph processing 3 | 4 | Testing Strategy: 5 | - Mock external NLP libraries and graph databases 6 | - Test core business logic for entity extraction and graph construction 7 | - Test triple generation and validation logic 8 | - Test URI construction and normalization 9 | - Test graph processing and traversal algorithms 10 | """ -------------------------------------------------------------------------------- /tests.manual/test-flow-stop-flow: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | 6 | url = "http://localhost:8088/" 7 | 8 | resp = requests.post( 9 | f"{url}/api/v1/flow", 10 | json={ 11 | "operation": "stop-flow", 12 | "flow-id": "0003", 13 | } 14 | ) 15 | 16 | print(resp) 17 | print(resp.text) 18 | resp = resp.json() 19 | 20 | 21 | print(resp) 22 | 23 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | torch 2 | urllib3 3 | transformers 4 | sentence-transformers 5 | rdflib 6 | pymilvus 7 | langchain 8 | langchain-core 9 | langchain-huggingface 10 | langchain-text-splitters 11 | langchain-community 12 | huggingface-hub 13 | requests 14 | scylla-driver 15 | pulsar-client 16 | pypdf 17 | anthropic 18 | google-cloud-aiplatform 19 | pyyaml 20 | prometheus-client 21 | pyarrow 22 | boto3 23 | ollama 24 | -------------------------------------------------------------------------------- /tests/unit/test_agent/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for agent processing and ReAct pattern logic 3 | 4 | Testing Strategy: 5 | - Mock external LLM calls and tool executions 6 | - Test core ReAct reasoning cycle logic (Think-Act-Observe) 7 | - Test tool selection and coordination algorithms 8 | - Test conversation state management and multi-turn reasoning 9 | - Test response synthesis and answer generation 10 | """ -------------------------------------------------------------------------------- /tests.manual/test-prompt-french-question: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.prompt_client import PromptClient 5 | 6 | p = PromptClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | question = """What is the square root of 16?""" 9 | 10 | resp = p.request( 11 | id="french-question", 12 | terms = { 13 | "question": question 14 | } 15 | ) 16 | 17 | print(resp) 18 | 19 | -------------------------------------------------------------------------------- /tests.manual/test-flow-start-flow: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | 6 | url = "http://localhost:8088/" 7 | 8 | resp = requests.post( 9 | f"{url}/api/v1/flow", 10 | json={ 11 | "operation": "start-flow", 12 | "flow-id": "0003", 13 | "class-name": "default", 14 | } 15 | ) 16 | 17 | print(resp) 18 | print(resp.text) 19 | resp = resp.json() 20 | 21 | 22 | print(resp) 23 | 24 | -------------------------------------------------------------------------------- /tests.manual/test-prompt-analyze: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import json 4 | from trustgraph.clients.prompt_client import PromptClient 5 | 6 | p = PromptClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | description = """Fred is a 4-legged cat who is 12 years old""" 9 | 10 | resp = p.request( 11 | id="analyze", 12 | terms = { 13 | "description": description, 14 | } 15 | ) 16 | 17 | print(json.dumps(resp, indent=4)) 18 | 19 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/__init__.py: -------------------------------------------------------------------------------- 1 | from .llm import * 2 | from .retrieval import * 3 | from .query import * 4 | from .agent import * 5 | from .flow import * 6 | from .prompt import * 7 | from .config import * 8 | from .library import * 9 | from .lookup import * 10 | from .nlp_query import * 11 | from .structured_query import * 12 | from .objects_query import * 13 | from .diagnosis import * 14 | from .collection import * 15 | from .storage import * -------------------------------------------------------------------------------- /tests.manual/test-prompt-spanish-question: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.prompt_client import PromptClient 5 | 6 | p = PromptClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | question = """What is the square root of 16?""" 9 | 10 | resp = p.request( 11 | id="question", 12 | terms = { 13 | "question": question, 14 | "attitude": "Spanish-speaking bot" 15 | } 16 | ) 17 | 18 | print(resp) 19 | 20 | -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/init_pulsar_manager.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CSRF_TOKEN=$(curl http://localhost:7750/pulsar-manager/csrf-token) 4 | 5 | curl \ 6 | -H "X-XSRF-TOKEN: $CSRF_TOKEN" \ 7 | -H "Cookie: XSRF-TOKEN=$CSRF_TOKEN;" \ 8 | -H 'Content-Type: application/json' \ 9 | -X PUT \ 10 | http://localhost:7750/pulsar-manager/users/superuser \ 11 | -d '{"name": "admin", "password": "apachepulsar", "description": "test", "email": "username@test.org"}' 12 | -------------------------------------------------------------------------------- /tests.manual/test-embeddings: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.embeddings_client import EmbeddingsClient 5 | 6 | embed = EmbeddingsClient( 7 | pulsar_host="pulsar://pulsar:6650", 8 | input_queue="non-persistent://tg/request/embeddings:default", 9 | output_queue="non-persistent://tg/response/embeddings:default", 10 | subscriber="test1", 11 | ) 12 | 13 | prompt="Write a funny limerick about a llama" 14 | 15 | resp = embed.request(prompt) 16 | 17 | print(resp) 18 | 19 | -------------------------------------------------------------------------------- /tests.manual/test-llm: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.llm_client import LlmClient 5 | 6 | llm = LlmClient( 7 | pulsar_host="pulsar://pulsar:6650", 8 | input_queue="non-persistent://tg/request/text-completion:default", 9 | output_queue="non-persistent://tg/response/text-completion:default", 10 | subscriber="test1", 11 | ) 12 | 13 | system = "You are a lovely assistant." 14 | prompt="what is 2 + 2 == 5" 15 | 16 | resp = llm.request(system, prompt) 17 | 18 | print(resp) 19 | 20 | -------------------------------------------------------------------------------- /tests.manual/test-doc-rag: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.document_rag_client import DocumentRagClient 5 | 6 | rag = DocumentRagClient( 7 | pulsar_host="pulsar://localhost:6650", 8 | subscriber="test1", 9 | input_queue = "non-persistent://tg/request/document-rag:default", 10 | output_queue = "non-persistent://tg/response/document-rag:default", 11 | ) 12 | 13 | query=""" 14 | What was the cause of the space shuttle disaster?""" 15 | 16 | resp = rag.request(query) 17 | 18 | print(resp) 19 | 20 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/parameter_spec.py: -------------------------------------------------------------------------------- 1 | 2 | from . spec import Spec 3 | 4 | class Parameter: 5 | def __init__(self, value): 6 | self.value = value 7 | async def start(): 8 | pass 9 | async def stop(): 10 | pass 11 | 12 | class ParameterSpec(Spec): 13 | def __init__(self, name): 14 | self.name = name 15 | 16 | def add(self, flow, processor, definition): 17 | 18 | value = definition.get(self.name, None) 19 | 20 | flow.parameter[self.name] = Parameter(value) 21 | 22 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/knowledge/rows.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, Array, Map, String 2 | 3 | from ..core.metadata import Metadata 4 | from ..core.primitives import RowSchema 5 | from ..core.topic import topic 6 | 7 | ############################################################################ 8 | 9 | # Stores rows of information 10 | 11 | class Rows(Record): 12 | metadata = Metadata() 13 | row_schema = RowSchema() 14 | rows = Array(Map(String())) 15 | 16 | ############################################################################ -------------------------------------------------------------------------------- /test-api/test-agent2-api: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "question": "What is 14 plus 12. Justify your answer.", 13 | } 14 | 15 | resp = requests.post( 16 | f"{url}agent", 17 | json=input, 18 | ) 19 | 20 | resp = resp.json() 21 | 22 | if "error" in resp: 23 | print(f"Error: {resp['error']}") 24 | sys.exit(1) 25 | 26 | print(resp["answer"]) 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests.manual/test-lang-topics: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.prompt_client import PromptClient 5 | 6 | p = PromptClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | chunk = """I noticed a cat in my garden. It is a four-legged animal 9 | which is a mammal and can be tame or wild. I wonder if it will be friends 10 | with me. I think the cat's name is Fred and it has 4 legs""" 11 | 12 | resp = p.request_topics( 13 | chunk=chunk, 14 | ) 15 | 16 | for d in resp: 17 | print(d.topic) 18 | print(" ", d.definition) 19 | 20 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/knowledge/identifier.py: -------------------------------------------------------------------------------- 1 | 2 | import uuid 3 | import hashlib 4 | 5 | def hash(data): 6 | 7 | if isinstance(data, str): 8 | data = data.encode("utf-8") 9 | 10 | # Create a SHA256 hash from the data 11 | id = hashlib.sha256(data).hexdigest() 12 | 13 | # Convert into a UUID, 64-byte hash becomes 32-byte UUID 14 | id = str(uuid.UUID(id[::2])) 15 | 16 | return id 17 | 18 | def to_uri(pref, id): 19 | return f"https://trustgraph.ai/{pref}/{id}" 20 | 21 | PREF_PUBEV = "pubev" 22 | PREF_ORG = "org" 23 | PREF_DOC = "doc" 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | __pycache__/ 3 | env/ 4 | */build/ 5 | *.egg-info/ 6 | *.parquet 7 | templates/values/version.jsonnet 8 | trustgraph-base/trustgraph/base_version.py 9 | trustgraph-cli/trustgraph/cli_version.py 10 | trustgraph-bedrock/trustgraph/bedrock_version.py 11 | trustgraph-embeddings-hf/trustgraph/embeddings_hf_version.py 12 | trustgraph-flow/trustgraph/flow_version.py 13 | trustgraph-ocr/trustgraph/ocr_version.py 14 | trustgraph-parquet/trustgraph/parquet_version.py 15 | trustgraph-vertexai/trustgraph/vertexai_version.py 16 | trustgraph-mcp/trustgraph/mcp_version.py 17 | vertexai/ -------------------------------------------------------------------------------- /tests.manual/test-prompt-question: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.prompt_client import PromptClient 5 | 6 | p = PromptClient( 7 | pulsar_host="pulsar://localhost:6650", 8 | input_queue="non-persistent://tg/request/prompt:default", 9 | output_queue="non-persistent://tg/response/prompt:default", 10 | subscriber="test1", 11 | ) 12 | 13 | question = """What is the square root of 16?""" 14 | 15 | resp = p.request( 16 | id="question", 17 | variables = { 18 | "question": question 19 | } 20 | ) 21 | 22 | print(resp) 23 | 24 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/auth.py: -------------------------------------------------------------------------------- 1 | 2 | class Authenticator: 3 | 4 | def __init__(self, token=None, allow_all=False): 5 | 6 | if not allow_all and token is None: 7 | raise RuntimeError("Need a token") 8 | 9 | if not allow_all and token == "": 10 | raise RuntimeError("Need a token") 11 | 12 | self.token = token 13 | self.allow_all = allow_all 14 | 15 | def permitted(self, token, roles): 16 | 17 | if self.allow_all: return True 18 | 19 | if self.token != token: return False 20 | 21 | return True 22 | 23 | -------------------------------------------------------------------------------- /tests.manual/query: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from trustgraph.graph_rag import GraphRag 4 | import sys 5 | 6 | query = " ".join(sys.argv[1:]) 7 | 8 | gr = GraphRag( 9 | verbose=True, 10 | pulsar_host="pulsar://localhost:6650", 11 | pr_request_queue="non-persistent://tg/request/prompt", 12 | pr_response_queue="non-persistent://tg/response/prompt-response", 13 | ) 14 | 15 | if query == "": 16 | query="""This knowledge graph describes the Space Shuttle disaster. 17 | Present 20 facts which are present in the knowledge graph.""" 18 | 19 | resp = gr.query(query) 20 | print(resp) 21 | 22 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/lookup.py: -------------------------------------------------------------------------------- 1 | 2 | from pulsar.schema import Record, String 3 | 4 | from ..core.primitives import Error, Value, Triple 5 | from ..core.topic import topic 6 | from ..core.metadata import Metadata 7 | 8 | ############################################################################ 9 | 10 | # Lookups 11 | 12 | class LookupRequest(Record): 13 | kind = String() 14 | term = String() 15 | 16 | class LookupResponse(Record): 17 | text = String() 18 | error = Error() 19 | 20 | ############################################################################ 21 | 22 | -------------------------------------------------------------------------------- /tests.manual/test-doc-embeddings: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.document_embeddings_client import DocumentEmbeddingsClient 5 | from trustgraph.clients.embeddings_client import EmbeddingsClient 6 | 7 | ec = EmbeddingsClient(pulsar_host="pulsar://localhost:6650") 8 | 9 | vectors = ec.request("What caused the space shuttle to explode?") 10 | 11 | print(vectors) 12 | 13 | llm = DocumentEmbeddingsClient(pulsar_host="pulsar://localhost:6650") 14 | 15 | limit=10 16 | 17 | resp = llm.request(vectors, limit) 18 | 19 | print("Response...") 20 | for val in resp: 21 | print(val) 22 | 23 | -------------------------------------------------------------------------------- /tests.manual/test-graph-embeddings: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.graph_embeddings_client import GraphEmbeddingsClient 5 | from trustgraph.clients.embeddings_client import EmbeddingsClient 6 | 7 | ec = EmbeddingsClient(pulsar_host="pulsar://localhost:6650") 8 | 9 | vectors = ec.request("What caused the space shuttle to explode?") 10 | 11 | print(vectors) 12 | 13 | llm = GraphEmbeddingsClient(pulsar_host="pulsar://localhost:6650") 14 | 15 | limit=10 16 | 17 | resp = llm.request(vectors, limit) 18 | 19 | print("Response...") 20 | for val in resp: 21 | print(val.value) 22 | 23 | -------------------------------------------------------------------------------- /test-api/test-dbpedia: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "term": "Cornwall", 13 | } 14 | 15 | resp = requests.post( 16 | f"{url}dbpedia", 17 | json=input, 18 | ) 19 | 20 | resp = resp.json() 21 | 22 | if "error" in resp: 23 | print(f"Error: {resp['error']}") 24 | sys.exit(1) 25 | 26 | print(resp["text"]) 27 | 28 | sys.exit(0) 29 | ############################################################################ 30 | 31 | -------------------------------------------------------------------------------- /tests.manual/test-lang-relationships: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.prompt_client import PromptClient 5 | 6 | p = PromptClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | chunk = """I noticed a cat in my garden. It is a four-legged animal 9 | which is a mammal and can be tame or wild. I wonder if it will be friends 10 | with me. I think the cat's name is Fred and it has 4 legs""" 11 | 12 | resp = p.request_relationships( 13 | chunk=chunk, 14 | ) 15 | 16 | for d in resp: 17 | print(d.s) 18 | print(" ", d.p) 19 | print(" ", d.o) 20 | print(" ", d.o_entity) 21 | 22 | -------------------------------------------------------------------------------- /test-api/test-encyclopedia: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "term": "Cornwall", 13 | } 14 | 15 | resp = requests.post( 16 | f"{url}encyclopedia", 17 | json=input, 18 | ) 19 | 20 | resp = resp.json() 21 | 22 | if "error" in resp: 23 | print(f"Error: {resp['error']}") 24 | sys.exit(1) 25 | 26 | print(resp["text"]) 27 | 28 | sys.exit(0) 29 | ############################################################################ 30 | 31 | -------------------------------------------------------------------------------- /test-api/test-internet-search: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "term": "Cornwall", 13 | } 14 | 15 | resp = requests.post( 16 | f"{url}internet-search", 17 | json=input, 18 | ) 19 | 20 | resp = resp.json() 21 | 22 | if "error" in resp: 23 | print(f"Error: {resp['error']}") 24 | sys.exit(1) 25 | 26 | print(resp["text"]) 27 | 28 | sys.exit(0) 29 | ############################################################################ 30 | 31 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/log_level.py: -------------------------------------------------------------------------------- 1 | 2 | from enum import Enum 3 | import _pulsar 4 | 5 | class LogLevel(Enum): 6 | DEBUG = 'debug' 7 | INFO = 'info' 8 | WARN = 'warn' 9 | ERROR = 'error' 10 | 11 | def __str__(self): 12 | return self.value 13 | 14 | def to_pulsar(self): 15 | if self == LogLevel.DEBUG: return _pulsar.LoggerLevel.Debug 16 | if self == LogLevel.INFO: return _pulsar.LoggerLevel.Info 17 | if self == LogLevel.WARN: return _pulsar.LoggerLevel.Warn 18 | if self == LogLevel.ERROR: return _pulsar.LoggerLevel.Error 19 | raise RuntimeError("Log level mismatch") 20 | 21 | -------------------------------------------------------------------------------- /test-api/test-embeddings-api: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/flow/0000/embeddings" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "text": "What is the highest risk aspect of running a space shuttle program? Provide 5 detailed reasons to justify our answer.", 13 | } 14 | 15 | resp = requests.post( 16 | url, 17 | json=input, 18 | ) 19 | 20 | resp = resp.json() 21 | 22 | if "error" in resp: 23 | print(f"Error: {resp['error']}") 24 | sys.exit(1) 25 | 26 | print(resp["vectors"]) 27 | 28 | -------------------------------------------------------------------------------- /tests.manual/test-lang-definition: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.prompt_client import PromptClient 5 | 6 | p = PromptClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | chunk = """I noticed a cat in my garden. It is a four-legged animal 9 | which is a mammal and can be tame or wild. I wonder if it will be friends 10 | with me. I think the cat's name is Fred and it has 4 legs. 11 | 12 | A cat is a small mammal. 13 | 14 | A grapefruit is a citrus fruit. 15 | 16 | """ 17 | 18 | resp = p.request_definitions( 19 | chunk=chunk, 20 | ) 21 | 22 | for d in resp: 23 | print(d.name, ":", d.definition) 24 | 25 | -------------------------------------------------------------------------------- /tests.manual/test-run-extract-row: -------------------------------------------------------------------------------- 1 | 2 | scripts/object-extract-row \ 3 | -p pulsar://localhost:6650 \ 4 | --field 'name:string:100:pri:Name of the person in the story' \ 5 | --field 'job:string:100::Job title or role' \ 6 | --field 'date:string:20::Date entered into role if known' \ 7 | --field 'supervisor:string:100::Supervisor or manager of this person, if known' \ 8 | --field 'location:string:100::Main base or location of work, if known' \ 9 | --field 'notes:string:1000::Additional notes or observations about this animal or person' \ 10 | --no-metrics \ 11 | --name actors \ 12 | --description 'Relevant people' 13 | 14 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/knowledge/nlp.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String, Boolean 2 | 3 | from ..core.topic import topic 4 | 5 | ############################################################################ 6 | 7 | # NLP extraction data types 8 | 9 | class Definition(Record): 10 | name = String() 11 | definition = String() 12 | 13 | class Topic(Record): 14 | name = String() 15 | definition = String() 16 | 17 | class Relationship(Record): 18 | s = String() 19 | p = String() 20 | o = String() 21 | o_entity = Boolean() 22 | 23 | class Fact(Record): 24 | s = String() 25 | p = String() 26 | o = String() -------------------------------------------------------------------------------- /tests.manual/test-graph-rag: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.graph_rag_client import GraphRagClient 5 | 6 | rag = GraphRagClient( 7 | pulsar_host="pulsar://localhost:6650", 8 | subscriber="test1", 9 | input_queue = "non-persistent://tg/request/graph-rag:default", 10 | output_queue = "non-persistent://tg/response/graph-rag:default", 11 | ) 12 | 13 | #query=""" 14 | #This knowledge graph describes the Space Shuttle disaster. 15 | #Present 20 facts which are present in the knowledge graph.""" 16 | 17 | query = "How many cats does Mark have?" 18 | 19 | resp = rag.request(query) 20 | 21 | print(resp) 22 | 23 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/agent/react/types.py: -------------------------------------------------------------------------------- 1 | 2 | import dataclasses 3 | from typing import Any, Dict 4 | 5 | @dataclasses.dataclass 6 | class Argument: 7 | name : str 8 | type : str 9 | description : str 10 | 11 | @dataclasses.dataclass 12 | class Tool: 13 | name : str 14 | description : str 15 | arguments : list[Argument] 16 | implementation : Any 17 | config : Dict[str, str] 18 | 19 | @dataclasses.dataclass 20 | class Action: 21 | thought : str 22 | name : str 23 | arguments : dict 24 | observation : str 25 | 26 | @dataclasses.dataclass 27 | class Final: 28 | thought : str 29 | final : str 30 | 31 | -------------------------------------------------------------------------------- /test-api/test-agent-api: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/flow/0000/agent" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "question": "What is the highest risk aspect of running a space shuttle program? Provide 5 detailed reasons to justify our answer.", 13 | } 14 | 15 | resp = requests.post( 16 | url, 17 | json=input, 18 | ) 19 | 20 | print(resp.text) 21 | resp = resp.json() 22 | 23 | if "error" in resp: 24 | print(f"Error: {resp['error']}") 25 | sys.exit(1) 26 | 27 | print(resp["answer"]) 28 | 29 | -------------------------------------------------------------------------------- /test-api/test-graph-rag-api: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/flow/0000/graph-rag" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "query": "Give me 10 facts", 13 | } 14 | 15 | resp = requests.post( 16 | url, 17 | json=input, 18 | ) 19 | 20 | resp = resp.json() 21 | 22 | print(resp) 23 | if "error" in resp: 24 | print(f"Error: {resp['error']}") 25 | sys.exit(1) 26 | 27 | print(resp["response"]) 28 | 29 | sys.exit(0) 30 | ############################################################################ 31 | 32 | -------------------------------------------------------------------------------- /tests/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | testpaths = tests 3 | python_paths = . 4 | python_files = test_*.py 5 | python_classes = Test* 6 | python_functions = test_* 7 | addopts = 8 | -v 9 | --tb=short 10 | --strict-markers 11 | --disable-warnings 12 | --cov=trustgraph 13 | --cov-report=html 14 | --cov-report=term-missing 15 | # --cov-fail-under=80 16 | asyncio_mode = auto 17 | markers = 18 | slow: marks tests as slow (deselect with '-m "not slow"') 19 | integration: marks tests as integration tests 20 | unit: marks tests as unit tests 21 | contract: marks tests as contract tests (service interface validation) 22 | vertexai: marks tests as vertex ai specific tests -------------------------------------------------------------------------------- /tests.manual/test-doc-prompt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from trustgraph.clients.prompt_client import PromptClient 5 | 6 | p = PromptClient(pulsar_host="pulsar://localhost:6650") 7 | 8 | docs = [ 9 | "In our house there is a big cat and a small cat.", 10 | "The small cat is black.", 11 | "The big cat is called Fred.", 12 | "The orange stripey cat is big.", 13 | "The black cat pounces on the big cat.", 14 | "The black cat is called Hope." 15 | ] 16 | 17 | query="What is the name of the cat who pounces on Fred? Provide a full explanation." 18 | 19 | resp = p.request_document_prompt( 20 | query=query, 21 | documents=docs, 22 | ) 23 | 24 | print(resp) 25 | 26 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/knowledge/structured.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String, Bytes, Map 2 | 3 | from ..core.metadata import Metadata 4 | from ..core.topic import topic 5 | 6 | ############################################################################ 7 | 8 | # Structured data submission for fire-and-forget processing 9 | 10 | class StructuredDataSubmission(Record): 11 | metadata = Metadata() 12 | format = String() # "json", "csv", "xml" 13 | schema_name = String() # Reference to schema in config 14 | data = Bytes() # Raw data to ingest 15 | options = Map(String()) # Format-specific options 16 | 17 | ############################################################################ -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/knowledge/object.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String, Map, Double, Array 2 | 3 | from ..core.metadata import Metadata 4 | from ..core.topic import topic 5 | 6 | ############################################################################ 7 | 8 | # Extracted object from text processing 9 | 10 | class ExtractedObject(Record): 11 | metadata = Metadata() 12 | schema_name = String() # Which schema this object belongs to 13 | values = Array(Map(String())) # Array of objects, each object is field name -> value 14 | confidence = Double() 15 | source_span = String() # Text span where object was found 16 | 17 | ############################################################################ -------------------------------------------------------------------------------- /test-api/test-llm2-api: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "system": "", 13 | "prompt": "Add 2 and 3" 14 | } 15 | 16 | resp = requests.post( 17 | f"{url}text-completion", 18 | json=input, 19 | ) 20 | 21 | if resp.status_code != 200: 22 | raise RuntimeError(f"Status code: {resp.status_code}") 23 | 24 | resp = resp.json() 25 | 26 | if "error" in resp: 27 | print(f"Error: {resp['error']}") 28 | sys.exit(1) 29 | 30 | print(resp["response"]) 31 | 32 | ############################################################################ 33 | 34 | -------------------------------------------------------------------------------- /install_packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Install TrustGraph packages for testing 3 | 4 | echo "Installing TrustGraph packages..." 5 | 6 | # Install base package first (required by others) 7 | cd trustgraph-base 8 | pip install -e . 9 | cd .. 10 | 11 | # Install base package first (required by others) 12 | cd trustgraph-cli 13 | pip install -e . 14 | cd .. 15 | 16 | # Install vertexai package (depends on base) 17 | cd trustgraph-vertexai 18 | pip install -e . 19 | cd .. 20 | 21 | # Install flow package (for additional components) 22 | cd trustgraph-flow 23 | pip install -e . 24 | cd .. 25 | 26 | echo "Package installation complete!" 27 | echo "Verify installation:" 28 | #python -c "import trustgraph.model.text_completion.vertexai.llm; print('VertexAI import successful')" 29 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/producer_spec.py: -------------------------------------------------------------------------------- 1 | 2 | from . producer import Producer 3 | from . metrics import ProducerMetrics 4 | from . spec import Spec 5 | 6 | class ProducerSpec(Spec): 7 | def __init__(self, name, schema): 8 | self.name = name 9 | self.schema = schema 10 | 11 | def add(self, flow, processor, definition): 12 | 13 | producer_metrics = ProducerMetrics( 14 | processor = flow.id, flow = flow.name, name = self.name 15 | ) 16 | 17 | producer = Producer( 18 | client = processor.pulsar_client, 19 | topic = definition[self.name], 20 | schema = self.schema, 21 | metrics = producer_metrics, 22 | ) 23 | 24 | flow.producer[self.name] = producer 25 | 26 | -------------------------------------------------------------------------------- /test-api/test-knowledge-list: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | input = { 14 | "operation": "list-kg-cores", 15 | "user": "trustgraph", 16 | } 17 | 18 | resp = requests.post( 19 | f"{url}knowledge", 20 | json=input, 21 | ) 22 | 23 | print(resp.text) 24 | resp = resp.json() 25 | 26 | print(resp) 27 | 28 | if "error" in resp: 29 | print(f"Error: {resp['error']}") 30 | sys.exit(1) 31 | 32 | # print(resp["response"]) 33 | print(resp) 34 | 35 | sys.exit(0) 36 | 37 | ############################################################################ 38 | 39 | -------------------------------------------------------------------------------- /test-api/test-library-list: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | 8 | url = "http://localhost:8088/api/v1/" 9 | 10 | ############################################################################ 11 | 12 | user = "trustgraph" 13 | 14 | input = { 15 | "operation": "list-documents", 16 | "user": user, 17 | } 18 | 19 | resp = requests.post( 20 | f"{url}librarian", 21 | json=input, 22 | ) 23 | 24 | print(resp.text) 25 | resp = resp.json() 26 | 27 | print(resp) 28 | 29 | if "error" in resp: 30 | print(f"Error: {resp['error']}") 31 | sys.exit(1) 32 | 33 | # print(resp["response"]) 34 | print(resp) 35 | 36 | sys.exit(0) 37 | 38 | ############################################################################ 39 | 40 | -------------------------------------------------------------------------------- /test-api/test-library-list-documents: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | input = { 14 | "operation": "list-documents", 15 | "user": "trustgraph", 16 | } 17 | 18 | resp = requests.post( 19 | f"{url}librarian", 20 | json=input, 21 | ) 22 | 23 | print(resp.text) 24 | resp = resp.json() 25 | 26 | print(resp) 27 | 28 | if "error" in resp: 29 | print(f"Error: {resp['error']}") 30 | sys.exit(1) 31 | 32 | # print(resp["response"]) 33 | print(resp) 34 | 35 | sys.exit(0) 36 | 37 | ############################################################################ 38 | 39 | -------------------------------------------------------------------------------- /test-api/test-library-list-processing: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | input = { 14 | "operation": "list-processing", 15 | "user": "trustgraph", 16 | } 17 | 18 | resp = requests.post( 19 | f"{url}librarian", 20 | json=input, 21 | ) 22 | 23 | print(resp.text) 24 | resp = resp.json() 25 | 26 | print(resp) 27 | 28 | if "error" in resp: 29 | print(f"Error: {resp['error']}") 30 | sys.exit(1) 31 | 32 | # print(resp["response"]) 33 | print(resp) 34 | 35 | sys.exit(0) 36 | 37 | ############################################################################ 38 | 39 | -------------------------------------------------------------------------------- /test-api/test-triples-query-api: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "p": { 13 | "v": "http://www.w3.org/2000/01/rdf-schema#label", 14 | "e": True, 15 | }, 16 | "limit": 10 17 | } 18 | 19 | resp = requests.post( 20 | f"{url}triples-query", 21 | json=input, 22 | ) 23 | 24 | print(resp.text) 25 | resp = resp.json() 26 | 27 | 28 | print(resp) 29 | if "error" in resp: 30 | print(f"Error: {resp['error']}") 31 | sys.exit(1) 32 | 33 | print(resp["response"]) 34 | 35 | sys.exit(0) 36 | 37 | ############################################################################ 38 | 39 | -------------------------------------------------------------------------------- /test-api/test-prompt-api: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/flow/0000/prompt" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "id": "question", 13 | "variables": { 14 | "question": "Write a joke about llamas." 15 | } 16 | } 17 | 18 | resp = requests.post( 19 | url, 20 | json=input, 21 | ) 22 | 23 | resp = resp.json() 24 | 25 | if "error" in resp: 26 | print(f"Error: {resp['error']}") 27 | sys.exit(1) 28 | 29 | if "object" in resp: 30 | print(f"Object: {resp['object']}") 31 | sys.exit(1) 32 | 33 | print(resp["text"]) 34 | 35 | sys.exit(0) 36 | ############################################################################ 37 | 38 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/structured_query.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String, Map, Array 2 | 3 | from ..core.primitives import Error 4 | from ..core.topic import topic 5 | 6 | ############################################################################ 7 | 8 | # Structured Query Service - executes GraphQL queries 9 | 10 | class StructuredQueryRequest(Record): 11 | question = String() 12 | user = String() # Cassandra keyspace identifier 13 | collection = String() # Data collection identifier 14 | 15 | class StructuredQueryResponse(Record): 16 | error = Error() 17 | data = String() # JSON-encoded GraphQL response data 18 | errors = Array(String()) # GraphQL errors if any 19 | 20 | ############################################################################ 21 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/document_load.py: -------------------------------------------------------------------------------- 1 | 2 | import base64 3 | import logging 4 | 5 | from ... schema import Document, Metadata 6 | from ... messaging import TranslatorRegistry 7 | 8 | from . sender import ServiceSender 9 | 10 | # Module logger 11 | logger = logging.getLogger(__name__) 12 | 13 | class DocumentLoad(ServiceSender): 14 | def __init__(self, pulsar_client, queue): 15 | 16 | super(DocumentLoad, self).__init__( 17 | pulsar_client = pulsar_client, 18 | queue = queue, 19 | schema = Document, 20 | ) 21 | 22 | self.translator = TranslatorRegistry.get_request_translator("document") 23 | 24 | def to_request(self, body): 25 | logger.info("Document received") 26 | return self.translator.to_pulsar(body) 27 | 28 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/text_load.py: -------------------------------------------------------------------------------- 1 | 2 | import base64 3 | import logging 4 | 5 | from ... schema import TextDocument, Metadata 6 | from ... messaging import TranslatorRegistry 7 | 8 | from . sender import ServiceSender 9 | 10 | # Module logger 11 | logger = logging.getLogger(__name__) 12 | 13 | class TextLoad(ServiceSender): 14 | def __init__(self, pulsar_client, queue): 15 | 16 | super(TextLoad, self).__init__( 17 | pulsar_client = pulsar_client, 18 | queue = queue, 19 | schema = TextDocument, 20 | ) 21 | 22 | self.translator = TranslatorRegistry.get_request_translator("text-document") 23 | 24 | def to_request(self, body): 25 | logger.info("Text document received") 26 | return self.translator.to_pulsar(body) 27 | 28 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | source = 3 | trustgraph-base/trustgraph 4 | trustgraph-flow/trustgraph 5 | trustgraph-bedrock/trustgraph 6 | trustgraph-vertexai/trustgraph 7 | trustgraph-embeddings-hf/trustgraph 8 | omit = 9 | */tests/* 10 | */test_* 11 | */conftest.py 12 | */__pycache__/* 13 | */venv/* 14 | */env/* 15 | */site-packages/* 16 | 17 | # Disable coverage warnings for contract tests 18 | disable_warnings = no-data-collected 19 | 20 | [report] 21 | exclude_lines = 22 | pragma: no cover 23 | def __repr__ 24 | raise AssertionError 25 | raise NotImplementedError 26 | if __name__ == .__main__.: 27 | class .*\(Protocol\): 28 | @(abc\.)?abstractmethod 29 | 30 | [html] 31 | directory = htmlcov 32 | skip_covered = False 33 | 34 | [xml] 35 | output = coverage.xml -------------------------------------------------------------------------------- /test-api/test-knowledge-delete: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | input = { 14 | "operation": "delete-kg-core", 15 | "id": "https://trustgraph.ai/doc/intelligence-and-state", 16 | "user": "trustgraph", 17 | } 18 | 19 | resp = requests.post( 20 | f"{url}knowledge", 21 | json=input, 22 | ) 23 | 24 | print(resp.text) 25 | resp = resp.json() 26 | 27 | print(resp) 28 | 29 | if "error" in resp: 30 | print(f"Error: {resp['error']}") 31 | sys.exit(1) 32 | 33 | # print(resp["response"]) 34 | print(resp) 35 | 36 | sys.exit(0) 37 | 38 | ############################################################################ 39 | 40 | -------------------------------------------------------------------------------- /test-api/test-knowledge-fetch: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | input = { 14 | "operation": "fetch-kg-core", 15 | "id": "https://trustgraph.ai/doc/intelligence-and-state", 16 | "user": "trustgraph", 17 | } 18 | 19 | resp = requests.post( 20 | f"{url}knowledge", 21 | json=input, 22 | ) 23 | 24 | print(resp.text) 25 | resp = resp.json() 26 | 27 | print(resp) 28 | 29 | if "error" in resp: 30 | print(f"Error: {resp['error']}") 31 | sys.exit(1) 32 | 33 | # print(resp["response"]) 34 | print(resp) 35 | 36 | sys.exit(0) 37 | 38 | ############################################################################ 39 | 40 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/knowledge/document.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, Bytes 2 | 3 | from ..core.metadata import Metadata 4 | from ..core.topic import topic 5 | 6 | ############################################################################ 7 | 8 | # PDF docs etc. 9 | class Document(Record): 10 | metadata = Metadata() 11 | data = Bytes() 12 | 13 | ############################################################################ 14 | 15 | # Text documents / text from PDF 16 | 17 | class TextDocument(Record): 18 | metadata = Metadata() 19 | text = Bytes() 20 | 21 | ############################################################################ 22 | 23 | # Chunks of text 24 | 25 | class Chunk(Record): 26 | metadata = Metadata() 27 | chunk = Bytes() 28 | 29 | ############################################################################ -------------------------------------------------------------------------------- /test-api/test-prompt2-api: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/flow/0000/prompt" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "id": "extract-definitions", 13 | "variables": { 14 | "text": "A cat is a large mammal." 15 | } 16 | } 17 | 18 | resp = requests.post( 19 | url, 20 | json=input, 21 | ) 22 | 23 | resp = resp.json() 24 | 25 | if "error" in resp: 26 | print(f"Error: {resp['error']}") 27 | sys.exit(1) 28 | 29 | if "object" in resp: 30 | object = json.loads(resp["object"]) 31 | print(json.dumps(object, indent=4)) 32 | sys.exit(1) 33 | 34 | print(resp["text"]) 35 | 36 | sys.exit(0) 37 | ############################################################################ 38 | 39 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/nlp_query.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String, Array, Map, Integer, Double 2 | 3 | from ..core.primitives import Error 4 | from ..core.topic import topic 5 | 6 | ############################################################################ 7 | 8 | # NLP to Structured Query Service - converts natural language to GraphQL 9 | 10 | class QuestionToStructuredQueryRequest(Record): 11 | question = String() 12 | max_results = Integer() 13 | 14 | class QuestionToStructuredQueryResponse(Record): 15 | error = Error() 16 | graphql_query = String() # Generated GraphQL query 17 | variables = Map(String()) # GraphQL variables if any 18 | detected_schemas = Array(String()) # Which schemas the query targets 19 | confidence = Double() 20 | 21 | ############################################################################ 22 | -------------------------------------------------------------------------------- /test-api/test-library-remove-processing: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | proc_id = "2714fc72-44ab-45f2-94dd-6773fc336535" 14 | 15 | input = { 16 | "operation": "remove-processing", 17 | "user": "trustgraph", 18 | "processing-id": proc_id, 19 | } 20 | 21 | resp = requests.post( 22 | f"{url}librarian", 23 | json=input, 24 | ) 25 | 26 | print(resp.text) 27 | resp = resp.json() 28 | 29 | print(resp) 30 | 31 | if "error" in resp: 32 | print(f"Error: {resp['error']}") 33 | sys.exit(1) 34 | 35 | # print(resp["response"]) 36 | print(resp) 37 | 38 | sys.exit(0) 39 | 40 | ############################################################################ 41 | 42 | -------------------------------------------------------------------------------- /tests.manual/test-load-pdf: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from pulsar.schema import JsonSchema 5 | import base64 6 | 7 | from trustgraph.schema import Document, Metadata 8 | 9 | client = pulsar.Client("pulsar://localhost:6650", listener_name="localhost") 10 | 11 | prod = client.create_producer( 12 | topic="persistent://tg/flow/document-load:0000", 13 | schema=JsonSchema(Document), 14 | chunking_enabled=True, 15 | ) 16 | 17 | path = "../sources/Challenger-Report-Vol1.pdf" 18 | 19 | with open(path, "rb") as f: 20 | blob = base64.b64encode(f.read()).decode("utf-8") 21 | 22 | message = Document( 23 | metadata = Metadata( 24 | id = "00001", 25 | metadata = [], 26 | user="trustgraph", 27 | collection="default", 28 | ), 29 | data=blob 30 | ) 31 | 32 | prod.send(message) 33 | 34 | prod.close() 35 | client.close() 36 | 37 | -------------------------------------------------------------------------------- /test-api/test-library-remove-document: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | id = "http://trustgraph.ai/doc/9fdee98b-b259-40ac-bcb9-8e82ccedeb04" 14 | 15 | input = { 16 | "operation": "remove-document", 17 | "user": "trustgraph", 18 | "document-id": id 19 | } 20 | 21 | resp = requests.post( 22 | f"{url}librarian", 23 | json=input, 24 | ) 25 | 26 | print(resp.text) 27 | resp = resp.json() 28 | 29 | print(resp) 30 | 31 | if "error" in resp: 32 | print(f"Error: {resp['error']}") 33 | sys.exit(1) 34 | 35 | # print(resp["response"]) 36 | print(resp) 37 | 38 | sys.exit(0) 39 | 40 | ############################################################################ 41 | 42 | -------------------------------------------------------------------------------- /test-api/test-library-remove-document2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | id = "http://trustgraph.ai/doc/6d034da9-2759-45c2-af24-14db7f4c44c2" 14 | 15 | input = { 16 | "operation": "remove-document", 17 | "user": "trustgraph", 18 | "document-id": id 19 | } 20 | 21 | resp = requests.post( 22 | f"{url}librarian", 23 | json=input, 24 | ) 25 | 26 | print(resp.text) 27 | resp = resp.json() 28 | 29 | print(resp) 30 | 31 | if "error" in resp: 32 | print(f"Error: {resp['error']}") 33 | sys.exit(1) 34 | 35 | # print(resp["response"]) 36 | print(resp) 37 | 38 | sys.exit(0) 39 | 40 | ############################################################################ 41 | 42 | -------------------------------------------------------------------------------- /test-api/test-library-get-document-content: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | 8 | url = "http://localhost:8088/api/v1/" 9 | 10 | ############################################################################ 11 | 12 | id = "http://trustgraph.ai/doc/9fdee98b-b259-40ac-bcb9-8e82ccedeb04" 13 | 14 | user = "trustgraph" 15 | 16 | input = { 17 | "operation": "get-document-content", 18 | "user": user, 19 | "document-id": id, 20 | } 21 | 22 | resp = requests.post( 23 | f"{url}librarian", 24 | json=input, 25 | ) 26 | 27 | resp = resp.json() 28 | 29 | if "error" in resp: 30 | print(f"Error: {resp['error']}") 31 | sys.exit(1) 32 | 33 | 34 | content = base64.b64decode(resp["content"]).decode("utf-8") 35 | 36 | print(content) 37 | 38 | sys.exit(0) 39 | 40 | ############################################################################ 41 | 42 | -------------------------------------------------------------------------------- /test-api/test-library-get-document-metadata: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | 8 | url = "http://localhost:8088/api/v1/" 9 | 10 | ############################################################################ 11 | 12 | id = "http://trustgraph.ai/doc/9fdee98b-b259-40ac-bcb9-8e82ccedeb04" 13 | 14 | user = "trustgraph" 15 | 16 | input = { 17 | "operation": "get-document-metadata", 18 | "user": user, 19 | "document-id": id, 20 | } 21 | 22 | resp = requests.post( 23 | f"{url}librarian", 24 | json=input, 25 | ) 26 | 27 | print(resp.text) 28 | resp = resp.json() 29 | 30 | print(resp) 31 | 32 | if "error" in resp: 33 | print(f"Error: {resp['error']}") 34 | sys.exit(1) 35 | 36 | # print(resp["response"]) 37 | print(resp) 38 | 39 | sys.exit(0) 40 | 41 | ############################################################################ 42 | 43 | -------------------------------------------------------------------------------- /tests.manual/test-load-text: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pulsar 4 | from pulsar.schema import JsonSchema 5 | import base64 6 | 7 | from trustgraph.schema import TextDocument, Metadata 8 | 9 | client = pulsar.Client("pulsar://localhost:6650", listener_name="localhost") 10 | 11 | prod = client.create_producer( 12 | topic="persistent://tg/flow/text-document-load:0000", 13 | schema=JsonSchema(TextDocument), 14 | chunking_enabled=True, 15 | ) 16 | 17 | path = "../trustgraph/docs/README.cats" 18 | 19 | with open(path, "r") as f: 20 | # blob = base64.b64encode(f.read()).decode("utf-8") 21 | blob = f.read() 22 | 23 | message = TextDocument( 24 | metadata = Metadata( 25 | id = "00001", 26 | metadata = [], 27 | user="trustgraph", 28 | collection="default", 29 | ), 30 | text=blob 31 | ) 32 | 33 | prod.send(message) 34 | 35 | prod.close() 36 | client.close() 37 | 38 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/knowledge/graph.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String, Array 2 | 3 | from ..core.primitives import Value, Triple 4 | from ..core.metadata import Metadata 5 | from ..core.topic import topic 6 | 7 | ############################################################################ 8 | 9 | # Entity context are an entity associated with textual context 10 | 11 | class EntityContext(Record): 12 | entity = Value() 13 | context = String() 14 | 15 | # This is a 'batching' mechanism for the above data 16 | class EntityContexts(Record): 17 | metadata = Metadata() 18 | entities = Array(EntityContext()) 19 | 20 | ############################################################################ 21 | 22 | # Graph triples 23 | 24 | class Triples(Record): 25 | metadata = Metadata() 26 | triples = Array(Triple()) 27 | 28 | ############################################################################ -------------------------------------------------------------------------------- /test-api/test-llm-api: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | 7 | url = "http://localhost:8088/api/v1/flow/0000/text-completion" 8 | 9 | ############################################################################ 10 | 11 | input = { 12 | "system": "Respond in French. Use long word, form of numbers, no digits", 13 | # "prompt": "Add 2 and 12" 14 | "prompt": "Add 12 and 14, and then make a poem about llamas which incorporates that number. Then write a joke about llamas" 15 | } 16 | 17 | resp = requests.post( 18 | url, 19 | json=input, 20 | ) 21 | 22 | if resp.status_code != 200: 23 | raise RuntimeError(f"Status code: {resp.status_code}") 24 | 25 | resp = resp.json() 26 | 27 | if "error" in resp: 28 | print(f"Error: {resp['error']}") 29 | sys.exit(1) 30 | 31 | print(resp["response"]) 32 | 33 | ############################################################################ 34 | 35 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/flow.py: -------------------------------------------------------------------------------- 1 | 2 | import asyncio 3 | 4 | class Flow: 5 | def __init__(self, id, flow, processor, defn): 6 | 7 | self.id = id 8 | self.name = flow 9 | 10 | self.producer = {} 11 | 12 | # Consumers and publishers. Is this a bit untidy? 13 | self.consumer = {} 14 | 15 | self.parameter = {} 16 | 17 | for spec in processor.specifications: 18 | spec.add(self, processor, defn) 19 | 20 | async def start(self): 21 | for c in self.consumer.values(): 22 | await c.start() 23 | 24 | async def stop(self): 25 | for c in self.consumer.values(): 26 | await c.stop() 27 | 28 | def __call__(self, key): 29 | if key in self.producer: return self.producer[key] 30 | if key in self.consumer: return self.consumer[key] 31 | if key in self.parameter: return self.parameter[key].value 32 | return None 33 | -------------------------------------------------------------------------------- /trustgraph-base/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "trustgraph-base" 7 | dynamic = ["version"] 8 | authors = [{name = "trustgraph.ai", email = "security@trustgraph.ai"}] 9 | description = "TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline." 10 | readme = "README.md" 11 | requires-python = ">=3.8" 12 | dependencies = [ 13 | "pulsar-client", 14 | "prometheus-client", 15 | "requests", 16 | ] 17 | classifiers = [ 18 | "Programming Language :: Python :: 3", 19 | "Operating System :: OS Independent", 20 | ] 21 | 22 | [project.urls] 23 | Homepage = "https://github.com/trustgraph-ai/trustgraph" 24 | 25 | [tool.setuptools.packages.find] 26 | include = ["trustgraph*"] 27 | 28 | [tool.setuptools.dynamic] 29 | version = {attr = "trustgraph.base_version.__version__"} -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/agent/react/README.md: -------------------------------------------------------------------------------- 1 | 2 | agent-manager-react \ 3 | -p pulsar://localhost:6650 \ 4 | --tool-type \ 5 | shuttle=knowledge-query:query \ 6 | cats=knowledge-query:query \ 7 | compute=text-completion:computation \ 8 | --tool-description \ 9 | shuttle="Query a knowledge base with information about the space shuttle. The query should be a simple natural language question" \ 10 | cats="Query a knowledge base with information about Mark's cats. The query should be a simple natural language question" \ 11 | compute="A computation engine which can answer questions about maths and computation" \ 12 | --tool-argument \ 13 | cats="query:string:The search query string" \ 14 | shuttle="query:string:The search query string" \ 15 | compute="computation:string:The computation to solve" 16 | 17 | 18 | --context 'The space shuttle challenger final mission was 58-L' 19 | 20 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/core/primitives.py: -------------------------------------------------------------------------------- 1 | 2 | from pulsar.schema import Record, String, Boolean, Array, Integer 3 | 4 | class Error(Record): 5 | type = String() 6 | message = String() 7 | 8 | class Value(Record): 9 | value = String() 10 | is_uri = Boolean() 11 | type = String() 12 | 13 | class Triple(Record): 14 | s = Value() 15 | p = Value() 16 | o = Value() 17 | 18 | class Field(Record): 19 | name = String() 20 | # int, string, long, bool, float, double, timestamp 21 | type = String() 22 | size = Integer() 23 | primary = Boolean() 24 | description = String() 25 | # NEW FIELDS for structured data: 26 | required = Boolean() # Whether field is required 27 | enum_values = Array(String()) # For enum type fields 28 | indexed = Boolean() # Whether field should be indexed 29 | 30 | class RowSchema(Record): 31 | name = String() 32 | description = String() 33 | fields = Array(Field()) 34 | 35 | -------------------------------------------------------------------------------- /tests/utils/__init__.py: -------------------------------------------------------------------------------- 1 | """Test utilities for TrustGraph tests""" 2 | 3 | from .streaming_assertions import ( 4 | assert_streaming_chunks_valid, 5 | assert_streaming_sequence, 6 | assert_agent_streaming_chunks, 7 | assert_rag_streaming_chunks, 8 | assert_streaming_completion, 9 | assert_streaming_content_matches, 10 | assert_no_empty_chunks, 11 | assert_streaming_error_handled, 12 | assert_chunk_types_valid, 13 | assert_streaming_latency_acceptable, 14 | assert_callback_invoked, 15 | ) 16 | 17 | __all__ = [ 18 | "assert_streaming_chunks_valid", 19 | "assert_streaming_sequence", 20 | "assert_agent_streaming_chunks", 21 | "assert_rag_streaming_chunks", 22 | "assert_streaming_completion", 23 | "assert_streaming_content_matches", 24 | "assert_no_empty_chunks", 25 | "assert_streaming_error_handled", 26 | "assert_chunk_types_valid", 27 | "assert_streaming_latency_acceptable", 28 | "assert_callback_invoked", 29 | ] 30 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/subscriber_spec.py: -------------------------------------------------------------------------------- 1 | 2 | from . metrics import SubscriberMetrics 3 | from . subscriber import Subscriber 4 | from . spec import Spec 5 | 6 | class SubscriberSpec(Spec): 7 | 8 | def __init__(self, name, schema): 9 | self.name = name 10 | self.schema = schema 11 | 12 | def add(self, flow, processor, definition): 13 | 14 | subscriber_metrics = SubscriberMetrics( 15 | processor = flow.id, flow = flow.name, name = self.name 16 | ) 17 | 18 | subscriber = Subscriber( 19 | client = processor.pulsar_client, 20 | topic = definition[self.name], 21 | subscription = flow.id, 22 | consumer_name = flow.id, 23 | schema = self.schema, 24 | metrics = subscriber_metrics, 25 | ) 26 | 27 | # Put it in the consumer map, does that work? 28 | # It means it gets start/stop call. 29 | flow.consumer[self.name] = subscriber 30 | 31 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/retrieval/nlp_query/pass1.txt: -------------------------------------------------------------------------------- 1 | You are a database schema selection expert. Given a natural language question and available 2 | database schemas, your job is to identify which schemas are most relevant to answer the question. 3 | 4 | ## Available Schemas: 5 | {% for schema in schemas %} 6 | **{{ schema.name }}**: {{ schema.description }} 7 | Fields: 8 | {% for field in schema.fields %} 9 | - {{ field.name }} ({{ field.type }}): {{ field.description }} 10 | {% endfor %} 11 | 12 | {% endfor %} 13 | 14 | ## Question: 15 | {{ question }} 16 | 17 | ## Instructions: 18 | 1. Analyze the question to understand what data is being requested 19 | 2. Examine each schema to understand what data it contains 20 | 3. Select ONLY the schemas that are directly relevant to answering the question 21 | 4. Return your answer as a JSON array of schema names 22 | 23 | ## Response Format: 24 | Return ONLY a JSON array of schema names, nothing else. 25 | Example: ["customers", "orders", "products"] 26 | -------------------------------------------------------------------------------- /trustgraph-mcp/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "trustgraph-mcp" 7 | dynamic = ["version"] 8 | authors = [{name = "trustgraph.ai", email = "security@trustgraph.ai"}] 9 | description = "TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline." 10 | readme = "README.md" 11 | requires-python = ">=3.8" 12 | dependencies = [ 13 | "mcp", 14 | "websockets", 15 | ] 16 | classifiers = [ 17 | "Programming Language :: Python :: 3", 18 | "Operating System :: OS Independent", 19 | ] 20 | 21 | [project.urls] 22 | Homepage = "https://github.com/trustgraph-ai/trustgraph" 23 | 24 | [project.scripts] 25 | mcp-server = "trustgraph.mcp_server:run" 26 | 27 | [tool.setuptools.packages.find] 28 | include = ["trustgraph*"] 29 | 30 | [tool.setuptools.dynamic] 31 | version = {attr = "trustgraph.mcp_version.__version__"} -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/embeddings_client.py: -------------------------------------------------------------------------------- 1 | 2 | from . request_response_spec import RequestResponse, RequestResponseSpec 3 | from .. schema import EmbeddingsRequest, EmbeddingsResponse 4 | 5 | class EmbeddingsClient(RequestResponse): 6 | async def embed(self, text, timeout=30): 7 | 8 | resp = await self.request( 9 | EmbeddingsRequest( 10 | text = text 11 | ), 12 | timeout=timeout 13 | ) 14 | 15 | if resp.error: 16 | raise RuntimeError(resp.error.message) 17 | 18 | return resp.vectors 19 | 20 | class EmbeddingsClientSpec(RequestResponseSpec): 21 | def __init__( 22 | self, request_name, response_name, 23 | ): 24 | super(EmbeddingsClientSpec, self).__init__( 25 | request_name = request_name, 26 | request_schema = EmbeddingsRequest, 27 | response_name = response_name, 28 | response_schema = EmbeddingsResponse, 29 | impl = EmbeddingsClient, 30 | ) 31 | 32 | -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/show_config.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dumps out the current configuration 3 | """ 4 | 5 | import argparse 6 | import os 7 | from trustgraph.api import Api 8 | import json 9 | 10 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 11 | 12 | def show_config(url): 13 | 14 | api = Api(url).config() 15 | 16 | config, version = api.all() 17 | 18 | print("Version:", version) 19 | print(json.dumps(config, indent=4)) 20 | 21 | def main(): 22 | 23 | parser = argparse.ArgumentParser( 24 | prog='tg-show-config', 25 | description=__doc__, 26 | ) 27 | 28 | parser.add_argument( 29 | '-u', '--api-url', 30 | default=default_url, 31 | help=f'API URL (default: {default_url})', 32 | ) 33 | 34 | args = parser.parse_args() 35 | 36 | try: 37 | 38 | show_config( 39 | url=args.api_url, 40 | ) 41 | 42 | except Exception as e: 43 | 44 | print("Exception:", e, flush=True) 45 | 46 | if __name__ == "__main__": 47 | main() -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/unused/dbpedia.py: -------------------------------------------------------------------------------- 1 | 2 | from .. schema import LookupRequest, LookupResponse 3 | from .. schema import dbpedia_lookup_request_queue 4 | from .. schema import dbpedia_lookup_response_queue 5 | 6 | from . endpoint import ServiceEndpoint 7 | from . requestor import ServiceRequestor 8 | 9 | class DbpediaRequestor(ServiceRequestor): 10 | def __init__(self, pulsar_client, timeout, auth): 11 | 12 | super(DbpediaRequestor, self).__init__( 13 | pulsar_client=pulsar_client, 14 | request_queue=dbpedia_lookup_request_queue, 15 | response_queue=dbpedia_lookup_response_queue, 16 | request_schema=LookupRequest, 17 | response_schema=LookupResponse, 18 | timeout=timeout, 19 | ) 20 | 21 | def to_request(self, body): 22 | return LookupRequest( 23 | term=body["term"], 24 | kind=body.get("kind", None), 25 | ) 26 | 27 | def from_response(self, message): 28 | return { "text": message.text }, True 29 | 30 | -------------------------------------------------------------------------------- /tests.manual/test-milvus: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from langchain_huggingface import HuggingFaceEmbeddings 4 | 5 | from trustgraph.direct.milvus import TripleVectors 6 | 7 | client = TripleVectors() 8 | 9 | embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2") 10 | 11 | text="""A cat is a small animal. A dog is a large animal. 12 | Cats say miaow. Dogs go woof. 13 | """ 14 | 15 | embeds = embeddings.embed_documents([text])[0] 16 | 17 | text2="""If you couldn't download the model due to network issues, as a walkaround, you can use random vectors to represent the text and still finish the example. Just note that the search result won't reflect semantic similarity as the vectors are fake ones. 18 | """ 19 | 20 | embeds2 = embeddings.embed_documents([text2])[0] 21 | 22 | client.insert(embeds, "animals") 23 | client.insert(embeds, "vectors") 24 | 25 | query="""What noise does a cat make?""" 26 | 27 | qembeds = embeddings.embed_documents([query])[0] 28 | 29 | res = client.search( 30 | qembeds, 31 | limit=2 32 | ) 33 | 34 | print(res) 35 | 36 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/unused/internet_search.py: -------------------------------------------------------------------------------- 1 | 2 | from .. schema import LookupRequest, LookupResponse 3 | from .. schema import internet_search_request_queue 4 | from .. schema import internet_search_response_queue 5 | 6 | from . endpoint import ServiceEndpoint 7 | from . requestor import ServiceRequestor 8 | 9 | class InternetSearchRequestor(ServiceRequestor): 10 | def __init__(self, pulsar_client, timeout, auth): 11 | 12 | super(InternetSearchRequestor, self).__init__( 13 | pulsar_client=pulsar_client, 14 | request_queue=internet_search_request_queue, 15 | response_queue=internet_search_response_queue, 16 | request_schema=LookupRequest, 17 | response_schema=LookupResponse, 18 | timeout=timeout, 19 | ) 20 | 21 | def to_request(self, body): 22 | return LookupRequest( 23 | term=body["term"], 24 | kind=body.get("kind", None), 25 | ) 26 | 27 | def from_response(self, message): 28 | return { "text": message.text }, True 29 | 30 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/unused/encyclopedia.py: -------------------------------------------------------------------------------- 1 | 2 | from .. schema import LookupRequest, LookupResponse 3 | from .. schema import encyclopedia_lookup_request_queue 4 | from .. schema import encyclopedia_lookup_response_queue 5 | 6 | from . endpoint import ServiceEndpoint 7 | from . requestor import ServiceRequestor 8 | 9 | class EncyclopediaRequestor(ServiceRequestor): 10 | def __init__(self, pulsar_client, timeout, auth): 11 | 12 | super(EncyclopediaRequestor, self).__init__( 13 | pulsar_client=pulsar_client, 14 | request_queue=encyclopedia_lookup_request_queue, 15 | response_queue=encyclopedia_lookup_response_queue, 16 | request_schema=LookupRequest, 17 | response_schema=LookupResponse, 18 | timeout=timeout, 19 | ) 20 | 21 | def to_request(self, body): 22 | return LookupRequest( 23 | term=body["term"], 24 | kind=body.get("kind", None), 25 | ) 26 | 27 | def from_response(self, message): 28 | return { "text": message.text }, True 29 | 30 | -------------------------------------------------------------------------------- /trustgraph/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "trustgraph" 7 | dynamic = ["version"] 8 | authors = [{name = "trustgraph.ai", email = "security@trustgraph.ai"}] 9 | description = "TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline." 10 | readme = "README.md" 11 | requires-python = ">=3.8" 12 | dependencies = [ 13 | "trustgraph-base>=1.7,<1.8", 14 | "trustgraph-bedrock>=1.7,<1.8", 15 | "trustgraph-cli>=1.7,<1.8", 16 | "trustgraph-embeddings-hf>=1.7,<1.8", 17 | "trustgraph-flow>=1.7,<1.8", 18 | "trustgraph-vertexai>=1.7,<1.8", 19 | ] 20 | classifiers = [ 21 | "Programming Language :: Python :: 3", 22 | "Operating System :: OS Independent", 23 | ] 24 | 25 | [project.urls] 26 | Homepage = "https://github.com/trustgraph-ai/trustgraph" 27 | 28 | [tool.setuptools] 29 | packages = ["trustgraph"] 30 | 31 | [tool.setuptools.dynamic] 32 | version = {attr = "trustgraph.trustgraph_version.__version__"} -------------------------------------------------------------------------------- /trustgraph-bedrock/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "trustgraph-bedrock" 7 | dynamic = ["version"] 8 | authors = [{name = "trustgraph.ai", email = "security@trustgraph.ai"}] 9 | description = "TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline." 10 | readme = "README.md" 11 | requires-python = ">=3.8" 12 | dependencies = [ 13 | "trustgraph-base>=1.7,<1.8", 14 | "pulsar-client", 15 | "prometheus-client", 16 | "boto3", 17 | ] 18 | classifiers = [ 19 | "Programming Language :: Python :: 3", 20 | "Operating System :: OS Independent", 21 | ] 22 | 23 | [project.urls] 24 | Homepage = "https://github.com/trustgraph-ai/trustgraph" 25 | 26 | [project.scripts] 27 | text-completion-bedrock = "trustgraph.model.text_completion.bedrock:run" 28 | 29 | [tool.setuptools.packages.find] 30 | include = ["trustgraph*"] 31 | 32 | [tool.setuptools.dynamic] 33 | version = {attr = "trustgraph.bedrock_version.__version__"} -------------------------------------------------------------------------------- /trustgraph-ocr/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "trustgraph-ocr" 7 | dynamic = ["version"] 8 | authors = [{name = "trustgraph.ai", email = "security@trustgraph.ai"}] 9 | description = "TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline." 10 | readme = "README.md" 11 | requires-python = ">=3.8" 12 | dependencies = [ 13 | "trustgraph-base>=1.7,<1.8", 14 | "pulsar-client", 15 | "prometheus-client", 16 | "boto3", 17 | "pdf2image", 18 | "pytesseract", 19 | ] 20 | classifiers = [ 21 | "Programming Language :: Python :: 3", 22 | "Operating System :: OS Independent", 23 | ] 24 | 25 | [project.urls] 26 | Homepage = "https://github.com/trustgraph-ai/trustgraph" 27 | 28 | [project.scripts] 29 | pdf-ocr = "trustgraph.decoding.ocr:run" 30 | 31 | [tool.setuptools.packages.find] 32 | include = ["trustgraph*"] 33 | 34 | [tool.setuptools.dynamic] 35 | version = {attr = "trustgraph.ocr_version.__version__"} -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/stop_flow.py: -------------------------------------------------------------------------------- 1 | """ 2 | Stops a processing flow. 3 | """ 4 | 5 | import argparse 6 | import os 7 | import tabulate 8 | from trustgraph.api import Api 9 | import json 10 | 11 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 12 | 13 | def stop_flow(url, flow_id): 14 | 15 | api = Api(url).flow() 16 | 17 | api.stop(id = flow_id) 18 | 19 | def main(): 20 | 21 | parser = argparse.ArgumentParser( 22 | prog='tg-stop-flow', 23 | description=__doc__, 24 | ) 25 | 26 | parser.add_argument( 27 | '-u', '--api-url', 28 | default=default_url, 29 | help=f'API URL (default: {default_url})', 30 | ) 31 | 32 | parser.add_argument( 33 | '-i', '--flow-id', 34 | required=True, 35 | help=f'Flow ID', 36 | ) 37 | 38 | args = parser.parse_args() 39 | 40 | try: 41 | 42 | stop_flow( 43 | url=args.api_url, 44 | flow_id=args.flow_id, 45 | ) 46 | 47 | except Exception as e: 48 | 49 | print("Exception:", e, flush=True) 50 | 51 | if __name__ == "__main__": 52 | main() -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/README.flows: -------------------------------------------------------------------------------- 1 | 2 | pdf- 3 | decoder 4 | 5 | | 6 | v 7 | 8 | chunker 9 | 10 | | 11 | ,------------------+----------- . . . 12 | | | 13 | v v 14 | 15 | extract- extract- 16 | relationships definitions 17 | 18 | | | | 19 | +----------------' | 20 | | v 21 | v 22 | vectorize 23 | triple- 24 | store | 25 | v 26 | 27 | ge-write 28 | 29 | Refactor: 30 | 31 | [] Change vectorize 32 | [] Re-route chunker to extract-* 33 | [] Re-route vectorize to ge-write* 34 | [] Re-route extract-definitions to ge-write* 35 | [] Remove extract-relationships to ge-write routing 36 | -------------------------------------------------------------------------------- /trustgraph-vertexai/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "trustgraph-vertexai" 7 | dynamic = ["version"] 8 | authors = [{name = "trustgraph.ai", email = "security@trustgraph.ai"}] 9 | description = "TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline." 10 | readme = "README.md" 11 | requires-python = ">=3.8" 12 | dependencies = [ 13 | "trustgraph-base>=1.7,<1.8", 14 | "pulsar-client", 15 | "google-cloud-aiplatform", 16 | "prometheus-client", 17 | "anthropic", 18 | ] 19 | classifiers = [ 20 | "Programming Language :: Python :: 3", 21 | "Operating System :: OS Independent", 22 | ] 23 | 24 | [project.urls] 25 | Homepage = "https://github.com/trustgraph-ai/trustgraph" 26 | 27 | [project.scripts] 28 | text-completion-vertexai = "trustgraph.model.text_completion.vertexai:run" 29 | 30 | [tool.setuptools.packages.find] 31 | include = ["trustgraph*"] 32 | 33 | [tool.setuptools.dynamic] 34 | version = {attr = "trustgraph.vertexai_version.__version__"} -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/graph_rag_client.py: -------------------------------------------------------------------------------- 1 | 2 | from . request_response_spec import RequestResponse, RequestResponseSpec 3 | from .. schema import GraphRagQuery, GraphRagResponse 4 | 5 | class GraphRagClient(RequestResponse): 6 | async def rag(self, query, user="trustgraph", collection="default", 7 | timeout=600): 8 | resp = await self.request( 9 | GraphRagQuery( 10 | query = query, 11 | user = user, 12 | collection = collection, 13 | ), 14 | timeout=timeout 15 | ) 16 | 17 | if resp.error: 18 | raise RuntimeError(resp.error.message) 19 | 20 | return resp.response 21 | 22 | class GraphRagClientSpec(RequestResponseSpec): 23 | def __init__( 24 | self, request_name, response_name, 25 | ): 26 | super(GraphRagClientSpec, self).__init__( 27 | request_name = request_name, 28 | request_schema = GraphRagQuery, 29 | response_name = response_name, 30 | response_schema = GraphRagResponse, 31 | impl = GraphRagClient, 32 | ) 33 | 34 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/api/types.py: -------------------------------------------------------------------------------- 1 | 2 | import dataclasses 3 | import datetime 4 | from typing import List 5 | from .. knowledge import hash, Uri, Literal 6 | 7 | @dataclasses.dataclass 8 | class Triple: 9 | s : str 10 | p : str 11 | o : str 12 | 13 | @dataclasses.dataclass 14 | class ConfigKey: 15 | type : str 16 | key : str 17 | 18 | @dataclasses.dataclass 19 | class ConfigValue: 20 | type : str 21 | key : str 22 | value : str 23 | 24 | @dataclasses.dataclass 25 | class DocumentMetadata: 26 | id : str 27 | time : datetime.datetime 28 | kind : str 29 | title : str 30 | comments : str 31 | metadata : List[Triple] 32 | user : str 33 | tags : List[str] 34 | 35 | @dataclasses.dataclass 36 | class ProcessingMetadata: 37 | id : str 38 | document_id : str 39 | time : datetime.datetime 40 | flow : str 41 | user : str 42 | collection : str 43 | tags : List[str] 44 | 45 | @dataclasses.dataclass 46 | class CollectionMetadata: 47 | user : str 48 | collection : str 49 | name : str 50 | description : str 51 | tags : List[str] 52 | created_at : str 53 | updated_at : str 54 | -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/delete_flow_class.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deletes a flow class 3 | """ 4 | 5 | import argparse 6 | import os 7 | import tabulate 8 | from trustgraph.api import Api 9 | import json 10 | 11 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 12 | 13 | def delete_flow_class(url, class_name): 14 | 15 | api = Api(url).flow() 16 | 17 | class_names = api.delete_class(class_name) 18 | 19 | def main(): 20 | 21 | parser = argparse.ArgumentParser( 22 | prog='tg-delete-flow-class', 23 | description=__doc__, 24 | ) 25 | 26 | parser.add_argument( 27 | '-u', '--api-url', 28 | default=default_url, 29 | help=f'API URL (default: {default_url})', 30 | ) 31 | 32 | parser.add_argument( 33 | '-n', '--class-name', 34 | help=f'Flow class name', 35 | ) 36 | 37 | args = parser.parse_args() 38 | 39 | try: 40 | 41 | delete_flow_class( 42 | url=args.api_url, 43 | class_name=args.class_name, 44 | ) 45 | 46 | except Exception as e: 47 | 48 | print("Exception:", e, flush=True) 49 | 50 | if __name__ == "__main__": 51 | main() -------------------------------------------------------------------------------- /test-api/test-library-add-processing: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | doc_id = "http://trustgraph.ai/doc/9fdee98b-b259-40ac-bcb9-8e82ccedeb04" 14 | 15 | proc_id = "2714fc72-44ab-45f2-94dd-6773fc336535" 16 | 17 | input = { 18 | "operation": "add-processing", 19 | "processing-metadata": { 20 | "id": proc_id, 21 | "document-id": doc_id, 22 | "time": int(time.time()), 23 | "flow": "0000", 24 | "user": "trustgraph", 25 | "collection": "default", 26 | "tags": ["test"], 27 | } 28 | } 29 | 30 | resp = requests.post( 31 | f"{url}librarian", 32 | json=input, 33 | ) 34 | 35 | print(resp.text) 36 | resp = resp.json() 37 | 38 | print(resp) 39 | 40 | if "error" in resp: 41 | print(f"Error: {resp['error']}") 42 | sys.exit(1) 43 | 44 | # print(resp["response"]) 45 | print(resp) 46 | 47 | sys.exit(0) 48 | 49 | ############################################################################ 50 | 51 | -------------------------------------------------------------------------------- /test-api/test-library-add-processing2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import json 5 | import sys 6 | import base64 7 | import time 8 | 9 | url = "http://localhost:8088/api/v1/" 10 | 11 | ############################################################################ 12 | 13 | doc_id = "http://trustgraph.ai/doc/6d034da9-2759-45c2-af24-14db7f4c44c2" 14 | 15 | proc_id = "72be9c56-a63a-4dde-8f3c-9b35f2598b83" 16 | 17 | input = { 18 | "operation": "add-processing", 19 | "processing-metadata": { 20 | "id": proc_id, 21 | "document-id": doc_id, 22 | "time": int(time.time()), 23 | "flow": "0000", 24 | "user": "trustgraph", 25 | "collection": "default", 26 | "tags": ["test"], 27 | } 28 | } 29 | 30 | resp = requests.post( 31 | f"{url}librarian", 32 | json=input, 33 | ) 34 | 35 | print(resp.text) 36 | resp = resp.json() 37 | 38 | print(resp) 39 | 40 | if "error" in resp: 41 | print(f"Error: {resp['error']}") 42 | sys.exit(1) 43 | 44 | # print(resp["response"]) 45 | print(resp) 46 | 47 | sys.exit(0) 48 | 49 | ############################################################################ 50 | 51 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/prompt.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String, Map, Boolean 2 | 3 | from ..core.primitives import Error 4 | from ..core.topic import topic 5 | 6 | ############################################################################ 7 | 8 | # Prompt services, abstract the prompt generation 9 | 10 | # extract-definitions: 11 | # chunk -> definitions 12 | # extract-relationships: 13 | # chunk -> relationships 14 | # kg-prompt: 15 | # query, triples -> answer 16 | # document-prompt: 17 | # query, documents -> answer 18 | # extract-rows 19 | # schema, chunk -> rows 20 | 21 | class PromptRequest(Record): 22 | id = String() 23 | 24 | # JSON encoded values 25 | terms = Map(String()) 26 | 27 | # Streaming support (default false for backward compatibility) 28 | streaming = Boolean() 29 | 30 | class PromptResponse(Record): 31 | 32 | # Error case 33 | error = Error() 34 | 35 | # Just plain text 36 | text = String() 37 | 38 | # JSON encoded 39 | object = String() 40 | 41 | # Indicates final message in stream 42 | end_of_stream = Boolean() 43 | 44 | ############################################################################ -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/show_processor_state.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dump out TrustGraph processor states. 3 | """ 4 | 5 | import requests 6 | import argparse 7 | 8 | default_metrics_url = "http://localhost:8088/api/metrics" 9 | 10 | def dump_status(url): 11 | 12 | url = f"{url}/query?query=processor_info" 13 | 14 | resp = requests.get(url) 15 | 16 | obj = resp.json() 17 | 18 | tbl = [ 19 | [ 20 | m["metric"]["job"], 21 | "\U0001f49a" 22 | ] 23 | for m in obj["data"]["result"] 24 | ] 25 | 26 | for row in tbl: 27 | print(f" {row[0]:30} {row[1]}") 28 | 29 | def main(): 30 | 31 | parser = argparse.ArgumentParser( 32 | prog='tg-show-processor-state', 33 | description=__doc__, 34 | ) 35 | 36 | parser.add_argument( 37 | '-m', '--metrics-url', 38 | default=default_metrics_url, 39 | help=f'Metrics URL (default: {default_metrics_url})', 40 | ) 41 | 42 | args = parser.parse_args() 43 | 44 | try: 45 | 46 | dump_status(args.metrics_url) 47 | 48 | except Exception as e: 49 | 50 | print("Exception:", e, flush=True) 51 | 52 | if __name__ == "__main__": 53 | main() -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/tool_client.py: -------------------------------------------------------------------------------- 1 | 2 | import json 3 | 4 | from . request_response_spec import RequestResponse, RequestResponseSpec 5 | from .. schema import ToolRequest, ToolResponse 6 | 7 | class ToolClient(RequestResponse): 8 | 9 | async def invoke(self, name, parameters={}, timeout=600): 10 | 11 | if parameters is None: 12 | parameters = {} 13 | 14 | resp = await self.request( 15 | ToolRequest( 16 | name = name, 17 | parameters = json.dumps(parameters), 18 | ), 19 | timeout=timeout 20 | ) 21 | 22 | if resp.error: 23 | raise RuntimeError(resp.error.message) 24 | 25 | if resp.text: return resp.text 26 | 27 | return json.loads(resp.object) 28 | 29 | class ToolClientSpec(RequestResponseSpec): 30 | def __init__( 31 | self, request_name, response_name, 32 | ): 33 | super(ToolClientSpec, self).__init__( 34 | request_name = request_name, 35 | request_schema = ToolRequest, 36 | response_name = response_name, 37 | response_schema = ToolResponse, 38 | impl = ToolClient, 39 | ) 40 | 41 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/clients/embeddings_client.py: -------------------------------------------------------------------------------- 1 | 2 | from pulsar.schema import JsonSchema 3 | from .. schema import EmbeddingsRequest, EmbeddingsResponse 4 | from . base import BaseClient 5 | 6 | import _pulsar 7 | 8 | # Ugly 9 | ERROR=_pulsar.LoggerLevel.Error 10 | WARN=_pulsar.LoggerLevel.Warn 11 | INFO=_pulsar.LoggerLevel.Info 12 | DEBUG=_pulsar.LoggerLevel.Debug 13 | 14 | class EmbeddingsClient(BaseClient): 15 | 16 | def __init__( 17 | self, log_level=ERROR, 18 | input_queue=None, 19 | output_queue=None, 20 | subscriber=None, 21 | pulsar_host="pulsar://pulsar:6650", 22 | pulsar_api_key=None, 23 | ): 24 | 25 | super(EmbeddingsClient, self).__init__( 26 | log_level=log_level, 27 | subscriber=subscriber, 28 | input_queue=input_queue, 29 | output_queue=output_queue, 30 | pulsar_host=pulsar_host, 31 | pulsar_api_key=pulsar_api_key, 32 | input_schema=EmbeddingsRequest, 33 | output_schema=EmbeddingsResponse, 34 | ) 35 | 36 | def request(self, text, timeout=300): 37 | return self.call(text=text, timeout=timeout).vectors 38 | 39 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/agent.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import AgentRequest, AgentResponse 3 | from ... messaging import TranslatorRegistry 4 | 5 | from . requestor import ServiceRequestor 6 | 7 | class AgentRequestor(ServiceRequestor): 8 | def __init__( 9 | self, pulsar_client, request_queue, response_queue, timeout, 10 | consumer, subscriber, 11 | ): 12 | 13 | super(AgentRequestor, self).__init__( 14 | pulsar_client=pulsar_client, 15 | request_queue=request_queue, 16 | response_queue=response_queue, 17 | request_schema=AgentRequest, 18 | response_schema=AgentResponse, 19 | subscription = subscriber, 20 | consumer_name = consumer, 21 | timeout=timeout, 22 | ) 23 | 24 | self.request_translator = TranslatorRegistry.get_request_translator("agent") 25 | self.response_translator = TranslatorRegistry.get_response_translator("agent") 26 | 27 | def to_request(self, body): 28 | return self.request_translator.to_pulsar(body) 29 | 30 | def from_response(self, message): 31 | return self.response_translator.from_response_with_completion(message) 32 | 33 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/mcp_tool.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import ToolRequest, ToolResponse 3 | from ... messaging import TranslatorRegistry 4 | 5 | from . requestor import ServiceRequestor 6 | 7 | class McpToolRequestor(ServiceRequestor): 8 | def __init__( 9 | self, pulsar_client, request_queue, response_queue, timeout, 10 | consumer, subscriber, 11 | ): 12 | 13 | super(McpToolRequestor, self).__init__( 14 | pulsar_client=pulsar_client, 15 | request_queue=request_queue, 16 | response_queue=response_queue, 17 | request_schema=ToolRequest, 18 | response_schema=ToolResponse, 19 | subscription = subscriber, 20 | consumer_name = consumer, 21 | timeout=timeout, 22 | ) 23 | 24 | self.request_translator = TranslatorRegistry.get_request_translator("tool") 25 | self.response_translator = TranslatorRegistry.get_response_translator("tool") 26 | 27 | def to_request(self, body): 28 | return self.request_translator.to_pulsar(body) 29 | 30 | def from_response(self, message): 31 | return self.response_translator.from_response_with_completion(message) 32 | 33 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/retrieval.py: -------------------------------------------------------------------------------- 1 | 2 | from pulsar.schema import Record, Bytes, String, Boolean, Integer, Array, Double 3 | from ..core.topic import topic 4 | from ..core.primitives import Error, Value 5 | 6 | ############################################################################ 7 | 8 | # Graph RAG text retrieval 9 | 10 | class GraphRagQuery(Record): 11 | query = String() 12 | user = String() 13 | collection = String() 14 | entity_limit = Integer() 15 | triple_limit = Integer() 16 | max_subgraph_size = Integer() 17 | max_path_length = Integer() 18 | streaming = Boolean() 19 | 20 | class GraphRagResponse(Record): 21 | error = Error() 22 | response = String() 23 | chunk = String() 24 | end_of_stream = Boolean() 25 | 26 | ############################################################################ 27 | 28 | # Document RAG text retrieval 29 | 30 | class DocumentRagQuery(Record): 31 | query = String() 32 | user = String() 33 | collection = String() 34 | doc_limit = Integer() 35 | streaming = Boolean() 36 | 37 | class DocumentRagResponse(Record): 38 | error = Error() 39 | response = String() 40 | chunk = String() 41 | end_of_stream = Boolean() 42 | 43 | -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/get_flow_class.py: -------------------------------------------------------------------------------- 1 | """ 2 | Outputs a flow class definition in JSON format. 3 | """ 4 | 5 | import argparse 6 | import os 7 | import tabulate 8 | from trustgraph.api import Api 9 | import json 10 | 11 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 12 | 13 | def get_flow_class(url, class_name): 14 | 15 | api = Api(url).flow() 16 | 17 | cls = api.get_class(class_name) 18 | 19 | print(json.dumps(cls, indent=4)) 20 | 21 | def main(): 22 | 23 | parser = argparse.ArgumentParser( 24 | prog='tg-get-flow-class', 25 | description=__doc__, 26 | ) 27 | 28 | parser.add_argument( 29 | '-u', '--api-url', 30 | default=default_url, 31 | help=f'API URL (default: {default_url})', 32 | ) 33 | 34 | parser.add_argument( 35 | '-n', '--class-name', 36 | required=True, 37 | help=f'Flow class name', 38 | ) 39 | 40 | args = parser.parse_args() 41 | 42 | try: 43 | 44 | get_flow_class( 45 | url=args.api_url, 46 | class_name=args.class_name, 47 | ) 48 | 49 | except Exception as e: 50 | 51 | print("Exception:", e, flush=True) 52 | 53 | if __name__ == "__main__": 54 | main() -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/flow.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import FlowRequest, FlowResponse 3 | from ... schema import flow_request_queue 4 | from ... schema import flow_response_queue 5 | from ... messaging import TranslatorRegistry 6 | 7 | from . requestor import ServiceRequestor 8 | 9 | class FlowRequestor(ServiceRequestor): 10 | def __init__(self, pulsar_client, consumer, subscriber, timeout=120): 11 | 12 | super(FlowRequestor, self).__init__( 13 | pulsar_client=pulsar_client, 14 | consumer_name = consumer, 15 | subscription = subscriber, 16 | request_queue=flow_request_queue, 17 | response_queue=flow_response_queue, 18 | request_schema=FlowRequest, 19 | response_schema=FlowResponse, 20 | timeout=timeout, 21 | ) 22 | 23 | self.request_translator = TranslatorRegistry.get_request_translator("flow") 24 | self.response_translator = TranslatorRegistry.get_response_translator("flow") 25 | 26 | def to_request(self, body): 27 | return self.request_translator.to_pulsar(body) 28 | 29 | def from_response(self, message): 30 | return self.response_translator.from_response_with_completion(message) 31 | 32 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/graph_rag.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import GraphRagQuery, GraphRagResponse 3 | from ... messaging import TranslatorRegistry 4 | 5 | from . requestor import ServiceRequestor 6 | 7 | class GraphRagRequestor(ServiceRequestor): 8 | def __init__( 9 | self, pulsar_client, request_queue, response_queue, timeout, 10 | consumer, subscriber, 11 | ): 12 | 13 | super(GraphRagRequestor, self).__init__( 14 | pulsar_client=pulsar_client, 15 | request_queue=request_queue, 16 | response_queue=response_queue, 17 | request_schema=GraphRagQuery, 18 | response_schema=GraphRagResponse, 19 | subscription = subscriber, 20 | consumer_name = consumer, 21 | timeout=timeout, 22 | ) 23 | 24 | self.request_translator = TranslatorRegistry.get_request_translator("graph-rag") 25 | self.response_translator = TranslatorRegistry.get_response_translator("graph-rag") 26 | 27 | def to_request(self, body): 28 | return self.request_translator.to_pulsar(body) 29 | 30 | def from_response(self, message): 31 | return self.response_translator.from_response_with_completion(message) 32 | 33 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/prompt.py: -------------------------------------------------------------------------------- 1 | 2 | import json 3 | 4 | from ... schema import PromptRequest, PromptResponse 5 | from ... messaging import TranslatorRegistry 6 | 7 | from . requestor import ServiceRequestor 8 | 9 | class PromptRequestor(ServiceRequestor): 10 | def __init__( 11 | self, pulsar_client, request_queue, response_queue, timeout, 12 | consumer, subscriber, 13 | ): 14 | 15 | super(PromptRequestor, self).__init__( 16 | pulsar_client=pulsar_client, 17 | request_queue=request_queue, 18 | response_queue=response_queue, 19 | request_schema=PromptRequest, 20 | response_schema=PromptResponse, 21 | subscription = subscriber, 22 | consumer_name = consumer, 23 | timeout=timeout, 24 | ) 25 | 26 | self.request_translator = TranslatorRegistry.get_request_translator("prompt") 27 | self.response_translator = TranslatorRegistry.get_response_translator("prompt") 28 | 29 | def to_request(self, body): 30 | return self.request_translator.to_pulsar(body) 31 | 32 | def from_response(self, message): 33 | return self.response_translator.from_response_with_completion(message) 34 | 35 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/agent_client.py: -------------------------------------------------------------------------------- 1 | 2 | from . request_response_spec import RequestResponse, RequestResponseSpec 3 | from .. schema import AgentRequest, AgentResponse 4 | from .. knowledge import Uri, Literal 5 | 6 | class AgentClient(RequestResponse): 7 | async def invoke(self, recipient, question, plan=None, state=None, 8 | history=[], timeout=300): 9 | 10 | resp = await self.request( 11 | AgentRequest( 12 | question = question, 13 | plan = plan, 14 | state = state, 15 | history = history, 16 | ), 17 | recipient=recipient, 18 | timeout=timeout, 19 | ) 20 | 21 | if resp.error: 22 | raise RuntimeError(resp.error.message) 23 | 24 | return resp.answer 25 | 26 | class AgentClientSpec(RequestResponseSpec): 27 | def __init__( 28 | self, request_name, response_name, 29 | ): 30 | super(AgentClientSpec, self).__init__( 31 | request_name = request_name, 32 | request_schema = AgentRequest, 33 | response_name = response_name, 34 | response_schema = AgentResponse, 35 | impl = AgentClient, 36 | ) 37 | 38 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/embeddings.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import EmbeddingsRequest, EmbeddingsResponse 3 | from ... messaging import TranslatorRegistry 4 | 5 | from . requestor import ServiceRequestor 6 | 7 | class EmbeddingsRequestor(ServiceRequestor): 8 | def __init__( 9 | self, pulsar_client, request_queue, response_queue, timeout, 10 | consumer, subscriber, 11 | ): 12 | 13 | super(EmbeddingsRequestor, self).__init__( 14 | pulsar_client=pulsar_client, 15 | request_queue=request_queue, 16 | response_queue=response_queue, 17 | request_schema=EmbeddingsRequest, 18 | response_schema=EmbeddingsResponse, 19 | subscription = subscriber, 20 | consumer_name = consumer, 21 | timeout=timeout, 22 | ) 23 | 24 | self.request_translator = TranslatorRegistry.get_request_translator("embeddings") 25 | self.response_translator = TranslatorRegistry.get_response_translator("embeddings") 26 | 27 | def to_request(self, body): 28 | return self.request_translator.to_pulsar(body) 29 | 30 | def from_response(self, message): 31 | return self.response_translator.from_response_with_completion(message) 32 | 33 | -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/show_kg_cores.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shows knowledge cores 3 | """ 4 | 5 | import argparse 6 | import os 7 | import tabulate 8 | from trustgraph.api import Api, ConfigKey 9 | import json 10 | 11 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 12 | 13 | def show_cores(url, user): 14 | 15 | api = Api(url).knowledge() 16 | 17 | ids = api.list_kg_cores() 18 | 19 | if len(ids) == 0: 20 | print("No knowledge cores.") 21 | 22 | for id in ids: 23 | print(id) 24 | 25 | def main(): 26 | 27 | parser = argparse.ArgumentParser( 28 | prog='tg-show-flows', 29 | description=__doc__, 30 | ) 31 | 32 | parser.add_argument( 33 | '-u', '--api-url', 34 | default=default_url, 35 | help=f'API URL (default: {default_url})', 36 | ) 37 | 38 | parser.add_argument( 39 | '-U', '--user', 40 | default="trustgraph", 41 | help='API URL (default: trustgraph)', 42 | ) 43 | 44 | args = parser.parse_args() 45 | 46 | try: 47 | 48 | show_cores( 49 | url=args.api_url, user=args.user 50 | ) 51 | 52 | except Exception as e: 53 | 54 | print("Exception:", e, flush=True) 55 | 56 | if __name__ == "__main__": 57 | main() -------------------------------------------------------------------------------- /trustgraph-embeddings-hf/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "trustgraph-embeddings-hf" 7 | dynamic = ["version"] 8 | authors = [{name = "trustgraph.ai", email = "security@trustgraph.ai"}] 9 | description = "HuggingFace embeddings support for TrustGraph." 10 | readme = "README.md" 11 | requires-python = ">=3.8" 12 | dependencies = [ 13 | "trustgraph-base>=1.7,<1.8", 14 | "trustgraph-flow>=1.7,<1.8", 15 | "torch", 16 | "urllib3", 17 | "transformers", 18 | "sentence-transformers", 19 | "langchain", 20 | "langchain-core", 21 | "langchain-huggingface", 22 | "langchain-community", 23 | "huggingface-hub", 24 | "pulsar-client", 25 | "pyyaml", 26 | "prometheus-client", 27 | ] 28 | classifiers = [ 29 | "Programming Language :: Python :: 3", 30 | "Operating System :: OS Independent", 31 | ] 32 | 33 | [project.urls] 34 | Homepage = "https://github.com/trustgraph-ai/trustgraph" 35 | 36 | [project.scripts] 37 | embeddings-hf = "trustgraph.embeddings.hf:run" 38 | 39 | [tool.setuptools.packages.find] 40 | include = ["trustgraph*"] 41 | 42 | [tool.setuptools.dynamic] 43 | version = {attr = "trustgraph.embeddings_hf_version.__version__"} -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/objects_query.py: -------------------------------------------------------------------------------- 1 | from ... schema import ObjectsQueryRequest, ObjectsQueryResponse 2 | from ... messaging import TranslatorRegistry 3 | 4 | from . requestor import ServiceRequestor 5 | 6 | class ObjectsQueryRequestor(ServiceRequestor): 7 | def __init__( 8 | self, pulsar_client, request_queue, response_queue, timeout, 9 | consumer, subscriber, 10 | ): 11 | 12 | super(ObjectsQueryRequestor, self).__init__( 13 | pulsar_client=pulsar_client, 14 | request_queue=request_queue, 15 | response_queue=response_queue, 16 | request_schema=ObjectsQueryRequest, 17 | response_schema=ObjectsQueryResponse, 18 | subscription = subscriber, 19 | consumer_name = consumer, 20 | timeout=timeout, 21 | ) 22 | 23 | self.request_translator = TranslatorRegistry.get_request_translator("objects-query") 24 | self.response_translator = TranslatorRegistry.get_response_translator("objects-query") 25 | 26 | def to_request(self, body): 27 | return self.request_translator.to_pulsar(body) 28 | 29 | def from_response(self, message): 30 | return self.response_translator.from_response_with_completion(message) -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/document_rag.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import DocumentRagQuery, DocumentRagResponse 3 | from ... messaging import TranslatorRegistry 4 | 5 | from . requestor import ServiceRequestor 6 | 7 | class DocumentRagRequestor(ServiceRequestor): 8 | def __init__( 9 | self, pulsar_client, request_queue, response_queue, timeout, 10 | consumer, subscriber, 11 | ): 12 | 13 | super(DocumentRagRequestor, self).__init__( 14 | pulsar_client=pulsar_client, 15 | request_queue=request_queue, 16 | response_queue=response_queue, 17 | request_schema=DocumentRagQuery, 18 | response_schema=DocumentRagResponse, 19 | subscription = subscriber, 20 | consumer_name = consumer, 21 | timeout=timeout, 22 | ) 23 | 24 | self.request_translator = TranslatorRegistry.get_request_translator("document-rag") 25 | self.response_translator = TranslatorRegistry.get_response_translator("document-rag") 26 | 27 | def to_request(self, body): 28 | return self.request_translator.to_pulsar(body) 29 | 30 | def from_response(self, message): 31 | return self.response_translator.from_response_with_completion(message) 32 | 33 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/config.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import ConfigRequest, ConfigResponse, ConfigKey, ConfigValue 3 | from ... schema import config_request_queue 4 | from ... schema import config_response_queue 5 | from ... messaging import TranslatorRegistry 6 | 7 | from . requestor import ServiceRequestor 8 | 9 | class ConfigRequestor(ServiceRequestor): 10 | def __init__(self, pulsar_client, consumer, subscriber, timeout=120): 11 | 12 | super(ConfigRequestor, self).__init__( 13 | pulsar_client=pulsar_client, 14 | consumer_name = consumer, 15 | subscription = subscriber, 16 | request_queue=config_request_queue, 17 | response_queue=config_response_queue, 18 | request_schema=ConfigRequest, 19 | response_schema=ConfigResponse, 20 | timeout=timeout, 21 | ) 22 | 23 | self.request_translator = TranslatorRegistry.get_request_translator("config") 24 | self.response_translator = TranslatorRegistry.get_response_translator("config") 25 | 26 | def to_request(self, body): 27 | return self.request_translator.to_pulsar(body) 28 | 29 | def from_response(self, message): 30 | return self.response_translator.from_response_with_completion(message) 31 | 32 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/structured_query.py: -------------------------------------------------------------------------------- 1 | from ... schema import StructuredQueryRequest, StructuredQueryResponse 2 | from ... messaging import TranslatorRegistry 3 | 4 | from . requestor import ServiceRequestor 5 | 6 | class StructuredQueryRequestor(ServiceRequestor): 7 | def __init__( 8 | self, pulsar_client, request_queue, response_queue, timeout, 9 | consumer, subscriber, 10 | ): 11 | 12 | super(StructuredQueryRequestor, self).__init__( 13 | pulsar_client=pulsar_client, 14 | request_queue=request_queue, 15 | response_queue=response_queue, 16 | request_schema=StructuredQueryRequest, 17 | response_schema=StructuredQueryResponse, 18 | subscription = subscriber, 19 | consumer_name = consumer, 20 | timeout=timeout, 21 | ) 22 | 23 | self.request_translator = TranslatorRegistry.get_request_translator("structured-query") 24 | self.response_translator = TranslatorRegistry.get_response_translator("structured-query") 25 | 26 | def to_request(self, body): 27 | return self.request_translator.to_pulsar(body) 28 | 29 | def from_response(self, message): 30 | return self.response_translator.from_response_with_completion(message) -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/triples_query.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import TriplesQueryRequest, TriplesQueryResponse, Triples 3 | from ... messaging import TranslatorRegistry 4 | 5 | from . requestor import ServiceRequestor 6 | 7 | class TriplesQueryRequestor(ServiceRequestor): 8 | def __init__( 9 | self, pulsar_client, request_queue, response_queue, timeout, 10 | consumer, subscriber, 11 | ): 12 | 13 | super(TriplesQueryRequestor, self).__init__( 14 | pulsar_client=pulsar_client, 15 | request_queue=request_queue, 16 | response_queue=response_queue, 17 | request_schema=TriplesQueryRequest, 18 | response_schema=TriplesQueryResponse, 19 | subscription = subscriber, 20 | consumer_name = consumer, 21 | timeout=timeout, 22 | ) 23 | 24 | self.request_translator = TranslatorRegistry.get_request_translator("triples-query") 25 | self.response_translator = TranslatorRegistry.get_response_translator("triples-query") 26 | 27 | def to_request(self, body): 28 | return self.request_translator.to_pulsar(body) 29 | 30 | def from_response(self, message): 31 | return self.response_translator.from_response_with_completion(message) 32 | 33 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/messaging/translators/embeddings.py: -------------------------------------------------------------------------------- 1 | from typing import Dict, Any, Tuple 2 | from ...schema import EmbeddingsRequest, EmbeddingsResponse 3 | from .base import MessageTranslator 4 | 5 | 6 | class EmbeddingsRequestTranslator(MessageTranslator): 7 | """Translator for EmbeddingsRequest schema objects""" 8 | 9 | def to_pulsar(self, data: Dict[str, Any]) -> EmbeddingsRequest: 10 | return EmbeddingsRequest( 11 | text=data["text"] 12 | ) 13 | 14 | def from_pulsar(self, obj: EmbeddingsRequest) -> Dict[str, Any]: 15 | return { 16 | "text": obj.text 17 | } 18 | 19 | 20 | class EmbeddingsResponseTranslator(MessageTranslator): 21 | """Translator for EmbeddingsResponse schema objects""" 22 | 23 | def to_pulsar(self, data: Dict[str, Any]) -> EmbeddingsResponse: 24 | raise NotImplementedError("Response translation to Pulsar not typically needed") 25 | 26 | def from_pulsar(self, obj: EmbeddingsResponse) -> Dict[str, Any]: 27 | return { 28 | "vectors": obj.vectors 29 | } 30 | 31 | def from_response_with_completion(self, obj: EmbeddingsResponse) -> Tuple[Dict[str, Any], bool]: 32 | """Returns (response_dict, is_final)""" 33 | return self.from_pulsar(obj), True -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/nlp_query.py: -------------------------------------------------------------------------------- 1 | from ... schema import QuestionToStructuredQueryRequest, QuestionToStructuredQueryResponse 2 | from ... messaging import TranslatorRegistry 3 | 4 | from . requestor import ServiceRequestor 5 | 6 | class NLPQueryRequestor(ServiceRequestor): 7 | def __init__( 8 | self, pulsar_client, request_queue, response_queue, timeout, 9 | consumer, subscriber, 10 | ): 11 | 12 | super(NLPQueryRequestor, self).__init__( 13 | pulsar_client=pulsar_client, 14 | request_queue=request_queue, 15 | response_queue=response_queue, 16 | request_schema=QuestionToStructuredQueryRequest, 17 | response_schema=QuestionToStructuredQueryResponse, 18 | subscription = subscriber, 19 | consumer_name = consumer, 20 | timeout=timeout, 21 | ) 22 | 23 | self.request_translator = TranslatorRegistry.get_request_translator("nlp-query") 24 | self.response_translator = TranslatorRegistry.get_response_translator("nlp-query") 25 | 26 | def to_request(self, body): 27 | return self.request_translator.to_pulsar(body) 28 | 29 | def from_response(self, message): 30 | return self.response_translator.from_response_with_completion(message) -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/text_completion.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import TextCompletionRequest, TextCompletionResponse 3 | from ... messaging import TranslatorRegistry 4 | 5 | from . requestor import ServiceRequestor 6 | 7 | class TextCompletionRequestor(ServiceRequestor): 8 | def __init__( 9 | self, pulsar_client, request_queue, response_queue, timeout, 10 | consumer, subscriber, 11 | ): 12 | 13 | super(TextCompletionRequestor, self).__init__( 14 | pulsar_client=pulsar_client, 15 | request_queue=request_queue, 16 | response_queue=response_queue, 17 | request_schema=TextCompletionRequest, 18 | response_schema=TextCompletionResponse, 19 | subscription = subscriber, 20 | consumer_name = consumer, 21 | timeout=timeout, 22 | ) 23 | 24 | self.request_translator = TranslatorRegistry.get_request_translator("text-completion") 25 | self.response_translator = TranslatorRegistry.get_response_translator("text-completion") 26 | 27 | def to_request(self, body): 28 | return self.request_translator.to_pulsar(body) 29 | 30 | def from_response(self, message): 31 | return self.response_translator.from_response_with_completion(message) 32 | 33 | -------------------------------------------------------------------------------- /tests.manual/test-agent: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import json 4 | import textwrap 5 | from trustgraph.clients.agent_client import AgentClient 6 | 7 | def wrap(text, width=75): 8 | 9 | if text is None: text = "n/a" 10 | 11 | out = textwrap.wrap( 12 | text, width=width 13 | ) 14 | return "\n".join(out) 15 | 16 | def output(text, prefix="> ", width=78): 17 | 18 | out = textwrap.indent( 19 | text, prefix=prefix 20 | ) 21 | print(out) 22 | 23 | p = AgentClient( 24 | pulsar_host="pulsar://pulsar:6650", 25 | input_queue = "non-persistent://tg/request/agent:0000", 26 | output_queue = "non-persistent://tg/response/agent:0000", 27 | ) 28 | 29 | q = "How many cats does Mark have? Calculate that number raised to 0.4 power. Is that number lower than the numeric part of the mission identifier of the Space Shuttle Challenger on its last mission? If so, give me an apple pie recipe, otherwise return a poem about cheese." 30 | 31 | output(wrap(q), "\U00002753 ") 32 | print() 33 | 34 | def think(x): 35 | output(wrap(x), "\U0001f914 ") 36 | print() 37 | 38 | def observe(x): 39 | output(wrap(x), "\U0001f4a1 ") 40 | print() 41 | 42 | resp = p.request( 43 | question=q, think=think, observe=observe, 44 | ) 45 | 46 | output(resp, "\U0001f4ac ") 47 | print() 48 | 49 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/consumer_spec.py: -------------------------------------------------------------------------------- 1 | 2 | from . metrics import ConsumerMetrics 3 | from . consumer import Consumer 4 | from . spec import Spec 5 | 6 | class ConsumerSpec(Spec): 7 | def __init__(self, name, schema, handler, concurrency = 1): 8 | self.name = name 9 | self.schema = schema 10 | self.handler = handler 11 | self.concurrency = concurrency 12 | 13 | def add(self, flow, processor, definition): 14 | 15 | consumer_metrics = ConsumerMetrics( 16 | processor = flow.id, flow = flow.name, name = self.name, 17 | ) 18 | 19 | consumer = Consumer( 20 | taskgroup = processor.taskgroup, 21 | flow = flow, 22 | client = processor.pulsar_client, 23 | topic = definition[self.name], 24 | subscriber = processor.id + "--" + flow.name + "--" + self.name, 25 | schema = self.schema, 26 | handler = self.handler, 27 | metrics = consumer_metrics, 28 | concurrency = self.concurrency 29 | ) 30 | 31 | # Consumer handle gets access to producers and other 32 | # metadata 33 | consumer.id = flow.id 34 | consumer.name = self.name 35 | consumer.flow = flow 36 | 37 | flow.consumer[self.name] = consumer 38 | 39 | -------------------------------------------------------------------------------- /schema.ttl: -------------------------------------------------------------------------------- 1 | @prefix ns1: . 2 | @prefix rdf: . 3 | @prefix rdfs: . 4 | @prefix schema: . 5 | @prefix skos: . 6 | 7 | schema:subjectOf rdfs:label "subject of" . 8 | skos:definition rdfs:label "definition" . 9 | 10 | rdf:type rdfs:label "type" . 11 | 12 | schema:DigitalDocument rdfs:label "digital document" . 13 | schema:Organization rdfs:label "organization" . 14 | schema:PublicationEvent rdfs:label "publication event" . 15 | 16 | schema:copyrightNotice rdfs:label "copyright notice" . 17 | schema:copyrightHolder rdfs:label "copyright holder" . 18 | schema:copyrightYear rdfs:label "copyright year" . 19 | schema:license rdfs:label "license" . 20 | schema:publication rdfs:label "publication" . 21 | schema:startDate rdfs:label "start date" . 22 | schema:endDate rdfs:label "end date" . 23 | schema:publishedBy rdfs:label "published by" . 24 | schema:datePublished rdfs:label "date published" . 25 | schema:publication rdfs:label "publication" . 26 | schema:datePublished rdfs:label "date published" . 27 | schema:url rdfs:label "url" . 28 | schema:identifier rdfs:label "identifier" . 29 | schema:keywords rdfs:label "keyword" . 30 | 31 | skos:definition rdfs:label "definition" . 32 | 33 | -------------------------------------------------------------------------------- /tests/unit/test_cli/conftest.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shared fixtures for CLI unit tests. 3 | """ 4 | 5 | import pytest 6 | from unittest.mock import AsyncMock, MagicMock 7 | 8 | 9 | @pytest.fixture 10 | def mock_websocket_connection(): 11 | """Mock WebSocket connection for CLI tools.""" 12 | mock_ws = MagicMock() 13 | 14 | # Create simple async functions that don't leave coroutines hanging 15 | async def mock_send(data): 16 | return None 17 | 18 | async def mock_recv(): 19 | return "" 20 | 21 | async def mock_close(): 22 | return None 23 | 24 | mock_ws.send = mock_send 25 | mock_ws.recv = mock_recv 26 | mock_ws.close = mock_close 27 | return mock_ws 28 | 29 | 30 | @pytest.fixture 31 | def mock_pulsar_client(): 32 | """Mock Pulsar client for CLI tools that use messaging.""" 33 | mock_client = MagicMock() 34 | mock_client.create_consumer = MagicMock() 35 | mock_client.create_producer = MagicMock() 36 | mock_client.close = MagicMock() 37 | return mock_client 38 | 39 | 40 | @pytest.fixture 41 | def sample_metadata(): 42 | """Sample metadata structure used across CLI tools.""" 43 | return { 44 | "id": "test-doc-123", 45 | "metadata": [], 46 | "user": "test-user", 47 | "collection": "test-collection" 48 | } -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/remove_library_document.py: -------------------------------------------------------------------------------- 1 | """ 2 | Remove a document from the library 3 | """ 4 | 5 | import argparse 6 | import os 7 | import uuid 8 | 9 | from trustgraph.api import Api 10 | 11 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 12 | default_user = 'trustgraph' 13 | 14 | 15 | def remove_doc(url, user, id): 16 | 17 | api = Api(url).library() 18 | 19 | api.remove_document(user=user, id=id) 20 | 21 | def main(): 22 | 23 | parser = argparse.ArgumentParser( 24 | prog='tg-remove-library-document', 25 | description=__doc__, 26 | ) 27 | 28 | parser.add_argument( 29 | '-u', '--url', 30 | default=default_url, 31 | help=f'API URL (default: {default_url})', 32 | ) 33 | 34 | parser.add_argument( 35 | '-U', '--user', 36 | default=default_user, 37 | help=f'User ID (default: {default_user})' 38 | ) 39 | 40 | parser.add_argument( 41 | '--identifier', '--id', 42 | required=True, 43 | help=f'Document ID' 44 | ) 45 | 46 | args = parser.parse_args() 47 | 48 | try: 49 | 50 | remove_doc(args.url, args.user, args.identifier) 51 | 52 | except Exception as e: 53 | 54 | print("Exception:", e, flush=True) 55 | 56 | if __name__ == "__main__": 57 | main() -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/structured_diag.py: -------------------------------------------------------------------------------- 1 | from ... schema import StructuredDataDiagnosisRequest, StructuredDataDiagnosisResponse 2 | from ... messaging import TranslatorRegistry 3 | 4 | from . requestor import ServiceRequestor 5 | 6 | class StructuredDiagRequestor(ServiceRequestor): 7 | def __init__( 8 | self, pulsar_client, request_queue, response_queue, timeout, 9 | consumer, subscriber, 10 | ): 11 | 12 | super(StructuredDiagRequestor, self).__init__( 13 | pulsar_client=pulsar_client, 14 | request_queue=request_queue, 15 | response_queue=response_queue, 16 | request_schema=StructuredDataDiagnosisRequest, 17 | response_schema=StructuredDataDiagnosisResponse, 18 | subscription = subscriber, 19 | consumer_name = consumer, 20 | timeout=timeout, 21 | ) 22 | 23 | self.request_translator = TranslatorRegistry.get_request_translator("structured-diag") 24 | self.response_translator = TranslatorRegistry.get_response_translator("structured-diag") 25 | 26 | def to_request(self, body): 27 | return self.request_translator.to_pulsar(body) 28 | 29 | def from_response(self, message): 30 | return self.response_translator.from_response_with_completion(message) -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/graph_embeddings_query.py: -------------------------------------------------------------------------------- 1 | 2 | from ... schema import GraphEmbeddingsRequest, GraphEmbeddingsResponse 3 | from ... messaging import TranslatorRegistry 4 | 5 | from . requestor import ServiceRequestor 6 | 7 | class GraphEmbeddingsQueryRequestor(ServiceRequestor): 8 | def __init__( 9 | self, pulsar_client, request_queue, response_queue, timeout, 10 | consumer, subscriber, 11 | ): 12 | 13 | super(GraphEmbeddingsQueryRequestor, self).__init__( 14 | pulsar_client=pulsar_client, 15 | request_queue=request_queue, 16 | response_queue=response_queue, 17 | request_schema=GraphEmbeddingsRequest, 18 | response_schema=GraphEmbeddingsResponse, 19 | subscription = subscriber, 20 | consumer_name = consumer, 21 | timeout=timeout, 22 | ) 23 | 24 | self.request_translator = TranslatorRegistry.get_request_translator("graph-embeddings-query") 25 | self.response_translator = TranslatorRegistry.get_response_translator("graph-embeddings-query") 26 | 27 | def to_request(self, body): 28 | return self.request_translator.to_pulsar(body) 29 | 30 | def from_response(self, message): 31 | return self.response_translator.from_response_with_completion(message) 32 | 33 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/knowledge/defs.py: -------------------------------------------------------------------------------- 1 | 2 | IS_A = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' 3 | LABEL = 'http://www.w3.org/2000/01/rdf-schema#label' 4 | 5 | DIGITAL_DOCUMENT = 'https://schema.org/DigitalDocument' 6 | PUBLICATION_EVENT = 'https://schema.org/PublicationEvent' 7 | ORGANIZATION = 'https://schema.org/Organization' 8 | 9 | NAME = 'https://schema.org/name' 10 | DESCRIPTION = 'https://schema.org/description' 11 | COPYRIGHT_NOTICE = 'https://schema.org/copyrightNotice' 12 | COPYRIGHT_HOLDER = 'https://schema.org/copyrightHolder' 13 | COPYRIGHT_YEAR = 'https://schema.org/copyrightYear' 14 | LICENSE = 'https://schema.org/license' 15 | PUBLICATION = 'https://schema.org/publication' 16 | START_DATE = 'https://schema.org/startDate' 17 | END_DATE = 'https://schema.org/endDate' 18 | PUBLISHED_BY = 'https://schema.org/publishedBy' 19 | DATE_PUBLISHED = 'https://schema.org/datePublished' 20 | PUBLICATION = 'https://schema.org/publication' 21 | DATE_PUBLISHED = 'https://schema.org/datePublished' 22 | URL = 'https://schema.org/url' 23 | IDENTIFIER = 'https://schema.org/identifier' 24 | KEYWORD = 'https://schema.org/keywords' 25 | 26 | class Uri(str): 27 | def is_uri(self): return True 28 | def is_literal(self): return False 29 | 30 | class Literal(str): 31 | def is_uri(self): return False 32 | def is_literal(self): return True 33 | 34 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/triples_store_service.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | Triples store base class 4 | """ 5 | 6 | import logging 7 | 8 | from .. schema import Triples 9 | from .. base import FlowProcessor, ConsumerSpec 10 | from .. exceptions import TooManyRequests 11 | 12 | # Module logger 13 | logger = logging.getLogger(__name__) 14 | 15 | default_ident = "triples-write" 16 | 17 | class TriplesStoreService(FlowProcessor): 18 | 19 | def __init__(self, **params): 20 | 21 | id = params.get("id") 22 | 23 | super(TriplesStoreService, self).__init__(**params | { "id": id }) 24 | 25 | self.register_specification( 26 | ConsumerSpec( 27 | name = "input", 28 | schema = Triples, 29 | handler = self.on_message 30 | ) 31 | ) 32 | 33 | async def on_message(self, msg, consumer, flow): 34 | 35 | try: 36 | 37 | request = msg.value() 38 | 39 | await self.store_triples(request) 40 | 41 | except TooManyRequests as e: 42 | raise e 43 | 44 | except Exception as e: 45 | 46 | logger.error(f"Exception in triples store service: {e}", exc_info=True) 47 | raise e 48 | 49 | @staticmethod 50 | def add_args(parser): 51 | 52 | FlowProcessor.add_args(parser) 53 | 54 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/sender.py: -------------------------------------------------------------------------------- 1 | 2 | # Like ServiceRequestor, but just fire-and-forget instead of request/response 3 | 4 | import asyncio 5 | import uuid 6 | import logging 7 | 8 | from ... base import Publisher 9 | 10 | logger = logging.getLogger("sender") 11 | logger.setLevel(logging.INFO) 12 | 13 | class ServiceSender: 14 | 15 | def __init__( 16 | self, 17 | pulsar_client, 18 | queue, schema, 19 | ): 20 | 21 | self.pub = Publisher( 22 | pulsar_client, queue, 23 | schema=schema, 24 | ) 25 | 26 | async def start(self): 27 | await self.pub.start() 28 | 29 | async def stop(self): 30 | await self.pub.stop() 31 | 32 | def to_request(self, request): 33 | raise RuntimeError("Not defined") 34 | 35 | async def process(self, request, responder=None): 36 | 37 | try: 38 | 39 | await self.pub.send(None, self.to_request(request)) 40 | 41 | if responder: 42 | await responder({}, True) 43 | 44 | return {} 45 | 46 | except Exception as e: 47 | 48 | logging.error(f"Exception: {e}") 49 | 50 | err = { "error": str(e) } 51 | 52 | if responder: 53 | await responder(err, True) 54 | 55 | return err 56 | 57 | -------------------------------------------------------------------------------- /test-api/test-knowledge-fetch2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import asyncio 5 | import json 6 | import sys 7 | import base64 8 | import time 9 | from websockets.asyncio.client import connect 10 | 11 | url = "ws://localhost:8088/api/v1/socket" 12 | 13 | ############################################################################ 14 | 15 | async def run(): 16 | 17 | async with connect(url) as ws: 18 | 19 | req = { 20 | "id": "aa11", 21 | "service": "knowledge", 22 | "request": { 23 | "operation": "fetch-kg-core", 24 | "user": "trustgraph", 25 | "id": "https://trustgraph.ai/doc/intelligence-and-state" 26 | } 27 | } 28 | 29 | await ws.send(json.dumps(req)) 30 | 31 | while True: 32 | 33 | msg = await ws.recv() 34 | obj = json.loads(msg) 35 | 36 | print(obj) 37 | 38 | if "error" in obj: 39 | print(f"Error: {obj['error']}") 40 | break 41 | 42 | if "response" not in obj: continue 43 | 44 | if "eos" in obj["response"]: 45 | if obj["response"]["eos"]: 46 | break 47 | 48 | ############################################################################ 49 | 50 | asyncio.run(run()) 51 | -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/delete_kg_core.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deletes a flow class 3 | """ 4 | 5 | import argparse 6 | import os 7 | import tabulate 8 | from trustgraph.api import Api 9 | import json 10 | 11 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 12 | 13 | def delete_kg_core(url, user, id): 14 | 15 | api = Api(url).knowledge() 16 | 17 | class_names = api.delete_kg_core(user = user, id = id) 18 | 19 | def main(): 20 | 21 | parser = argparse.ArgumentParser( 22 | prog='tg-delete-kg-core', 23 | description=__doc__, 24 | ) 25 | 26 | parser.add_argument( 27 | '-u', '--api-url', 28 | default=default_url, 29 | help=f'API URL (default: {default_url})', 30 | ) 31 | 32 | parser.add_argument( 33 | '-U', '--user', 34 | default="trustgraph", 35 | help='API URL (default: trustgraph)', 36 | ) 37 | 38 | parser.add_argument( 39 | '--id', '--identifier', 40 | required=True, 41 | help=f'Knowledge core ID', 42 | ) 43 | 44 | args = parser.parse_args() 45 | 46 | try: 47 | 48 | delete_kg_core( 49 | url=args.api_url, 50 | user=args.user, 51 | id=args.id, 52 | ) 53 | 54 | except Exception as e: 55 | 56 | print("Exception:", e, flush=True) 57 | 58 | if __name__ == "__main__": 59 | main() 60 | -------------------------------------------------------------------------------- /run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Test runner script for TrustGraph 3 | 4 | echo "TrustGraph Test Runner" 5 | echo "====================" 6 | 7 | # Check if we're in the right directory 8 | if [ ! -f "install_packages.sh" ]; then 9 | echo "❌ Error: Please run this script from the project root directory" 10 | echo " Expected files: install_packages.sh, check_imports.py" 11 | exit 1 12 | fi 13 | 14 | # Step 1: Check current imports 15 | echo "Step 1: Checking current imports..." 16 | python check_imports.py 17 | 18 | # Step 2: Install packages if needed 19 | echo "" 20 | echo "Step 2: Installing TrustGraph packages..." 21 | echo "This may take a moment..." 22 | ./install_packages.sh 23 | 24 | # Step 3: Check imports again 25 | echo "" 26 | echo "Step 3: Verifying imports after installation..." 27 | python check_imports.py 28 | 29 | # Step 4: Install test dependencies 30 | echo "" 31 | echo "Step 4: Installing test dependencies..." 32 | cd tests/ 33 | pip install -r requirements.txt 34 | cd .. 35 | 36 | # Step 5: Run the tests 37 | echo "" 38 | echo "Step 5: Running VertexAI tests..." 39 | echo "Command: pytest tests/unit/test_text_completion/test_vertexai_processor.py -v" 40 | echo "" 41 | 42 | # Set Python path just in case 43 | export PYTHONPATH=$PWD:$PYTHONPATH 44 | 45 | pytest tests/unit/test_text_completion/test_vertexai_processor.py -v 46 | 47 | echo "" 48 | echo "Test run complete!" -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/structured_query_client.py: -------------------------------------------------------------------------------- 1 | from . request_response_spec import RequestResponse, RequestResponseSpec 2 | from .. schema import StructuredQueryRequest, StructuredQueryResponse 3 | 4 | class StructuredQueryClient(RequestResponse): 5 | async def structured_query(self, question, user="trustgraph", collection="default", timeout=600): 6 | resp = await self.request( 7 | StructuredQueryRequest( 8 | question = question, 9 | user = user, 10 | collection = collection 11 | ), 12 | timeout=timeout 13 | ) 14 | 15 | if resp.error: 16 | raise RuntimeError(resp.error.message) 17 | 18 | # Return the full response structure for the tool to handle 19 | return { 20 | "data": resp.data, 21 | "errors": resp.errors if resp.errors else [], 22 | "error": resp.error 23 | } 24 | 25 | class StructuredQueryClientSpec(RequestResponseSpec): 26 | def __init__( 27 | self, request_name, response_name, 28 | ): 29 | super(StructuredQueryClientSpec, self).__init__( 30 | request_name = request_name, 31 | request_schema = StructuredQueryRequest, 32 | response_name = response_name, 33 | response_schema = StructuredQueryResponse, 34 | impl = StructuredQueryClient, 35 | ) -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/knowledge.py: -------------------------------------------------------------------------------- 1 | 2 | import base64 3 | 4 | from ... schema import KnowledgeRequest, KnowledgeResponse, Triples 5 | from ... schema import GraphEmbeddings, Metadata, EntityEmbeddings 6 | from ... schema import knowledge_request_queue 7 | from ... schema import knowledge_response_queue 8 | from ... messaging import TranslatorRegistry 9 | 10 | from . requestor import ServiceRequestor 11 | 12 | class KnowledgeRequestor(ServiceRequestor): 13 | def __init__(self, pulsar_client, consumer, subscriber, timeout=120): 14 | 15 | super(KnowledgeRequestor, self).__init__( 16 | pulsar_client=pulsar_client, 17 | consumer_name = consumer, 18 | subscription = subscriber, 19 | request_queue=knowledge_request_queue, 20 | response_queue=knowledge_response_queue, 21 | request_schema=KnowledgeRequest, 22 | response_schema=KnowledgeResponse, 23 | timeout=timeout, 24 | ) 25 | 26 | self.request_translator = TranslatorRegistry.get_request_translator("knowledge") 27 | self.response_translator = TranslatorRegistry.get_response_translator("knowledge") 28 | 29 | def to_request(self, body): 30 | return self.request_translator.to_pulsar(body) 31 | 32 | def from_response(self, message): 33 | return self.response_translator.from_response_with_completion(message) 34 | 35 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/objects_query.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String, Map, Array 2 | 3 | from ..core.primitives import Error 4 | from ..core.topic import topic 5 | 6 | ############################################################################ 7 | 8 | # Objects Query Service - executes GraphQL queries against structured data 9 | 10 | class GraphQLError(Record): 11 | message = String() 12 | path = Array(String()) # Path to the field that caused the error 13 | extensions = Map(String()) # Additional error metadata 14 | 15 | class ObjectsQueryRequest(Record): 16 | user = String() # Cassandra keyspace (follows pattern from TriplesQueryRequest) 17 | collection = String() # Data collection identifier (required for partition key) 18 | query = String() # GraphQL query string 19 | variables = Map(String()) # GraphQL variables 20 | operation_name = String() # Operation to execute for multi-operation documents 21 | 22 | class ObjectsQueryResponse(Record): 23 | error = Error() # System-level error (connection, timeout, etc.) 24 | data = String() # JSON-encoded GraphQL response data 25 | errors = Array(GraphQLError()) # GraphQL field-level errors 26 | extensions = Map(String()) # Query metadata (execution time, etc.) 27 | 28 | ############################################################################ -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/put_flow_class.py: -------------------------------------------------------------------------------- 1 | """ 2 | Uploads a flow class definition. You can take the output of 3 | tg-get-flow-class and load it back in using this utility. 4 | """ 5 | 6 | import argparse 7 | import os 8 | from trustgraph.api import Api 9 | import json 10 | 11 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 12 | 13 | def put_flow_class(url, class_name, config): 14 | 15 | api = Api(url) 16 | 17 | class_names = api.flow().put_class(class_name, config) 18 | 19 | def main(): 20 | 21 | parser = argparse.ArgumentParser( 22 | prog='tg-put-flow-class', 23 | description=__doc__, 24 | ) 25 | 26 | parser.add_argument( 27 | '-u', '--api-url', 28 | default=default_url, 29 | help=f'API URL (default: {default_url})', 30 | ) 31 | 32 | parser.add_argument( 33 | '-n', '--class-name', 34 | help=f'Flow class name', 35 | ) 36 | 37 | parser.add_argument( 38 | '-c', '--config', 39 | help=f'Initial configuration to load, should be raw JSON', 40 | ) 41 | 42 | args = parser.parse_args() 43 | 44 | try: 45 | 46 | put_flow_class( 47 | url=args.api_url, 48 | class_name=args.class_name, 49 | config=json.loads(args.config), 50 | ) 51 | 52 | except Exception as e: 53 | 54 | print("Exception:", e, flush=True) 55 | 56 | if __name__ == "__main__": 57 | main() -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/graph_embeddings_store_service.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | Graph embeddings store base class 4 | """ 5 | 6 | import logging 7 | 8 | from .. schema import GraphEmbeddings 9 | from .. base import FlowProcessor, ConsumerSpec 10 | from .. exceptions import TooManyRequests 11 | 12 | # Module logger 13 | logger = logging.getLogger(__name__) 14 | 15 | default_ident = "graph-embeddings-write" 16 | 17 | class GraphEmbeddingsStoreService(FlowProcessor): 18 | 19 | def __init__(self, **params): 20 | 21 | id = params.get("id") 22 | 23 | super(GraphEmbeddingsStoreService, self).__init__( 24 | **params | { "id": id } 25 | ) 26 | 27 | self.register_specification( 28 | ConsumerSpec( 29 | name = "input", 30 | schema = GraphEmbeddings, 31 | handler = self.on_message 32 | ) 33 | ) 34 | 35 | async def on_message(self, msg, consumer, flow): 36 | 37 | try: 38 | 39 | request = msg.value() 40 | 41 | await self.store_graph_embeddings(request) 42 | 43 | except TooManyRequests as e: 44 | raise e 45 | 46 | except Exception as e: 47 | 48 | logger.error(f"Exception in graph embeddings store service: {e}", exc_info=True) 49 | raise e 50 | 51 | @staticmethod 52 | def add_args(parser): 53 | 54 | FlowProcessor.add_args(parser) 55 | 56 | -------------------------------------------------------------------------------- /trustgraph-flow/trustgraph/gateway/dispatch/collection_management.py: -------------------------------------------------------------------------------- 1 | from ... schema import CollectionManagementRequest, CollectionManagementResponse 2 | from ... schema import collection_request_queue, collection_response_queue 3 | from ... messaging import TranslatorRegistry 4 | 5 | from . requestor import ServiceRequestor 6 | 7 | class CollectionManagementRequestor(ServiceRequestor): 8 | def __init__(self, pulsar_client, consumer, subscriber, timeout=120): 9 | 10 | super(CollectionManagementRequestor, self).__init__( 11 | pulsar_client=pulsar_client, 12 | consumer_name = consumer, 13 | subscription = subscriber, 14 | request_queue=collection_request_queue, 15 | response_queue=collection_response_queue, 16 | request_schema=CollectionManagementRequest, 17 | response_schema=CollectionManagementResponse, 18 | timeout=timeout, 19 | ) 20 | 21 | self.request_translator = TranslatorRegistry.get_request_translator("collection-management") 22 | self.response_translator = TranslatorRegistry.get_response_translator("collection-management") 23 | 24 | def to_request(self, body): 25 | print("REQUEST", body, flush=True) 26 | return self.request_translator.to_pulsar(body) 27 | 28 | def from_response(self, message): 29 | print("RESPONSE", message, flush=True) 30 | return self.response_translator.from_response_with_completion(message) 31 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/document_embeddings_store_service.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | Document embeddings store base class 4 | """ 5 | 6 | import logging 7 | 8 | from .. schema import DocumentEmbeddings 9 | from .. base import FlowProcessor, ConsumerSpec 10 | from .. exceptions import TooManyRequests 11 | 12 | # Module logger 13 | logger = logging.getLogger(__name__) 14 | 15 | default_ident = "document-embeddings-write" 16 | 17 | class DocumentEmbeddingsStoreService(FlowProcessor): 18 | 19 | def __init__(self, **params): 20 | 21 | id = params.get("id") 22 | 23 | super(DocumentEmbeddingsStoreService, self).__init__( 24 | **params | { "id": id } 25 | ) 26 | 27 | self.register_specification( 28 | ConsumerSpec( 29 | name = "input", 30 | schema = DocumentEmbeddings, 31 | handler = self.on_message 32 | ) 33 | ) 34 | 35 | async def on_message(self, msg, consumer, flow): 36 | 37 | try: 38 | 39 | request = msg.value() 40 | 41 | await self.store_document_embeddings(request) 42 | 43 | except TooManyRequests as e: 44 | raise e 45 | 46 | except Exception as e: 47 | 48 | logger.error(f"Exception in document embeddings store service: {e}", exc_info=True) 49 | raise e 50 | 51 | @staticmethod 52 | def add_args(parser): 53 | 54 | FlowProcessor.add_args(parser) 55 | 56 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/knowledge/organization.py: -------------------------------------------------------------------------------- 1 | 2 | from . defs import * 3 | 4 | def Value(value, is_uri): 5 | if is_uri: 6 | return Uri(value) 7 | else: 8 | return Literal(value) 9 | 10 | def Triple(s, p, o): 11 | return { 12 | "s": s, "p": p, "o": o, 13 | } 14 | 15 | class Organization: 16 | def __init__(self, id, name=None, description=None): 17 | self.id = id 18 | self.name = name 19 | self.description = description 20 | 21 | def emit(self, emit): 22 | 23 | emit(Triple( 24 | s=Value(value=self.id, is_uri=True), 25 | p=Value(value=IS_A, is_uri=True), 26 | o=Value(value=ORGANIZATION, is_uri=True) 27 | )) 28 | 29 | if self.name: 30 | 31 | emit(Triple( 32 | s=Value(value=self.id, is_uri=True), 33 | p=Value(value=LABEL, is_uri=True), 34 | o=Value(value=self.name, is_uri=False) 35 | )) 36 | 37 | emit(Triple( 38 | s=Value(value=self.id, is_uri=True), 39 | p=Value(value=NAME, is_uri=True), 40 | o=Value(value=self.name, is_uri=False) 41 | )) 42 | 43 | if self.description: 44 | 45 | emit(Triple( 46 | s=Value(value=self.id, is_uri=True), 47 | p=Value(value=DESCRIPTION, is_uri=True), 48 | o=Value(value=self.description, is_uri=False) 49 | )) 50 | 51 | -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/delete_config_item.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deletes a configuration item 3 | """ 4 | 5 | import argparse 6 | import os 7 | from trustgraph.api import Api 8 | from trustgraph.api.types import ConfigKey 9 | 10 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 11 | 12 | def delete_config_item(url, config_type, key): 13 | 14 | api = Api(url).config() 15 | 16 | config_key = ConfigKey(type=config_type, key=key) 17 | api.delete([config_key]) 18 | 19 | print(f"Configuration item deleted: {config_type}/{key}") 20 | 21 | def main(): 22 | 23 | parser = argparse.ArgumentParser( 24 | prog='tg-delete-config-item', 25 | description=__doc__, 26 | ) 27 | 28 | parser.add_argument( 29 | '--type', 30 | required=True, 31 | help='Configuration type', 32 | ) 33 | 34 | parser.add_argument( 35 | '--key', 36 | required=True, 37 | help='Configuration key', 38 | ) 39 | 40 | parser.add_argument( 41 | '-u', '--api-url', 42 | default=default_url, 43 | help=f'API URL (default: {default_url})', 44 | ) 45 | 46 | args = parser.parse_args() 47 | 48 | try: 49 | 50 | delete_config_item( 51 | url=args.api_url, 52 | config_type=args.type, 53 | key=args.key, 54 | ) 55 | 56 | except Exception as e: 57 | 58 | print("Exception:", e, flush=True) 59 | 60 | if __name__ == "__main__": 61 | main() -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/llm.py: -------------------------------------------------------------------------------- 1 | 2 | from pulsar.schema import Record, String, Array, Double, Integer, Boolean 3 | 4 | from ..core.topic import topic 5 | from ..core.primitives import Error 6 | 7 | ############################################################################ 8 | 9 | # LLM text completion 10 | 11 | class TextCompletionRequest(Record): 12 | system = String() 13 | prompt = String() 14 | streaming = Boolean() # Default false for backward compatibility 15 | 16 | class TextCompletionResponse(Record): 17 | error = Error() 18 | response = String() 19 | in_token = Integer() 20 | out_token = Integer() 21 | model = String() 22 | end_of_stream = Boolean() # Indicates final message in stream 23 | 24 | ############################################################################ 25 | 26 | # Embeddings 27 | 28 | class EmbeddingsRequest(Record): 29 | text = String() 30 | 31 | class EmbeddingsResponse(Record): 32 | error = Error() 33 | vectors = Array(Array(Double())) 34 | 35 | ############################################################################ 36 | 37 | # Tool request/response 38 | 39 | class ToolRequest(Record): 40 | name = String() 41 | 42 | # Parameters are JSON encoded 43 | parameters = String() 44 | 45 | class ToolResponse(Record): 46 | error = Error() 47 | 48 | # Plain text aka "unstructured" 49 | text = String() 50 | 51 | # JSON-encoded object aka "structured" 52 | object = String() 53 | 54 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/base/document_embeddings_client.py: -------------------------------------------------------------------------------- 1 | 2 | import logging 3 | 4 | from . request_response_spec import RequestResponse, RequestResponseSpec 5 | from .. schema import DocumentEmbeddingsRequest, DocumentEmbeddingsResponse 6 | from .. knowledge import Uri, Literal 7 | 8 | # Module logger 9 | logger = logging.getLogger(__name__) 10 | 11 | class DocumentEmbeddingsClient(RequestResponse): 12 | async def query(self, vectors, limit=20, user="trustgraph", 13 | collection="default", timeout=30): 14 | 15 | resp = await self.request( 16 | DocumentEmbeddingsRequest( 17 | vectors = vectors, 18 | limit = limit, 19 | user = user, 20 | collection = collection 21 | ), 22 | timeout=timeout 23 | ) 24 | 25 | logger.debug(f"Document embeddings response: {resp}") 26 | 27 | if resp.error: 28 | raise RuntimeError(resp.error.message) 29 | 30 | return resp.chunks 31 | 32 | class DocumentEmbeddingsClientSpec(RequestResponseSpec): 33 | def __init__( 34 | self, request_name, response_name, 35 | ): 36 | super(DocumentEmbeddingsClientSpec, self).__init__( 37 | request_name = request_name, 38 | request_schema = DocumentEmbeddingsRequest, 39 | response_name = response_name, 40 | response_schema = DocumentEmbeddingsResponse, 41 | impl = DocumentEmbeddingsClient, 42 | ) 43 | 44 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/clients/document_rag_client.py: -------------------------------------------------------------------------------- 1 | 2 | import _pulsar 3 | 4 | from .. schema import DocumentRagQuery, DocumentRagResponse 5 | from .. schema import document_rag_request_queue, document_rag_response_queue 6 | from . base import BaseClient 7 | 8 | # Ugly 9 | ERROR=_pulsar.LoggerLevel.Error 10 | WARN=_pulsar.LoggerLevel.Warn 11 | INFO=_pulsar.LoggerLevel.Info 12 | DEBUG=_pulsar.LoggerLevel.Debug 13 | 14 | class DocumentRagClient(BaseClient): 15 | 16 | def __init__( 17 | self, 18 | log_level=ERROR, 19 | subscriber=None, 20 | input_queue=None, 21 | output_queue=None, 22 | pulsar_host="pulsar://pulsar:6650", 23 | pulsar_api_key=None, 24 | ): 25 | 26 | if input_queue == None: 27 | input_queue = document_rag_request_queue 28 | 29 | if output_queue == None: 30 | output_queue = document_rag_response_queue 31 | 32 | super(DocumentRagClient, self).__init__( 33 | log_level=log_level, 34 | subscriber=subscriber, 35 | input_queue=input_queue, 36 | output_queue=output_queue, 37 | pulsar_host=pulsar_host, 38 | pulsar_api_key=pulsar_api_key, 39 | input_schema=DocumentRagQuery, 40 | output_schema=DocumentRagResponse, 41 | ) 42 | 43 | def request(self, query, timeout=300): 44 | 45 | return self.call( 46 | query=query, timeout=timeout 47 | ).response 48 | 49 | -------------------------------------------------------------------------------- /.github/workflows/pull-request.yaml: -------------------------------------------------------------------------------- 1 | 2 | name: Test pull request 3 | 4 | on: 5 | pull_request: 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | 12 | test: 13 | 14 | name: Run tests 15 | runs-on: ubuntu-latest 16 | 17 | container: 18 | image: python:3.13 19 | 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@v3 23 | 24 | - name: Setup packages 25 | run: make update-package-versions VERSION=1.7.999 26 | 27 | - name: Setup environment 28 | run: python3 -m venv env 29 | 30 | - name: Invoke environment 31 | run: . env/bin/activate 32 | 33 | - name: Install trustgraph-base 34 | run: (cd trustgraph-base; pip install .) 35 | 36 | - name: Install trustgraph-cli 37 | run: (cd trustgraph-cli; pip install .) 38 | 39 | - name: Install trustgraph-flow 40 | run: (cd trustgraph-flow; pip install .) 41 | 42 | - name: Install trustgraph-vertexai 43 | run: (cd trustgraph-vertexai; pip install .) 44 | 45 | - name: Install trustgraph-bedrock 46 | run: (cd trustgraph-bedrock; pip install .) 47 | 48 | - name: Install some stuff 49 | run: pip install pytest pytest-cov pytest-asyncio pytest-mock 50 | 51 | - name: Unit tests 52 | run: pytest tests/unit 53 | 54 | - name: Integration tests (cut the out the long-running tests) 55 | run: pytest tests/integration -m 'not slow' 56 | 57 | - name: Contract tests 58 | run: pytest tests/contract 59 | 60 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/diagnosis.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String, Map, Double, Array 2 | from ..core.primitives import Error 3 | 4 | ############################################################################ 5 | 6 | # Structured data diagnosis services 7 | 8 | class StructuredDataDiagnosisRequest(Record): 9 | operation = String() # "detect-type", "generate-descriptor", "diagnose", or "schema-selection" 10 | sample = String() # Data sample to analyze (text content) 11 | type = String() # Data type (csv, json, xml) - optional, required for generate-descriptor 12 | schema_name = String() # Target schema name for descriptor generation - optional 13 | 14 | # JSON encoded options (e.g., delimiter for CSV) 15 | options = Map(String()) 16 | 17 | class StructuredDataDiagnosisResponse(Record): 18 | error = Error() 19 | 20 | operation = String() # The operation that was performed 21 | detected_type = String() # Detected data type (for detect-type/diagnose) - optional 22 | confidence = Double() # Confidence score for type detection - optional 23 | 24 | # JSON encoded descriptor (for generate-descriptor/diagnose) - optional 25 | descriptor = String() 26 | 27 | # JSON encoded additional metadata (e.g., field count, sample records) 28 | metadata = Map(String()) 29 | 30 | # Array of matching schema IDs (for schema-selection operation) - optional 31 | schema_matches = Array(String()) 32 | 33 | ############################################################################ -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/agent.py: -------------------------------------------------------------------------------- 1 | 2 | from pulsar.schema import Record, String, Array, Map, Boolean 3 | 4 | from ..core.topic import topic 5 | from ..core.primitives import Error 6 | 7 | ############################################################################ 8 | 9 | # Prompt services, abstract the prompt generation 10 | 11 | class AgentStep(Record): 12 | thought = String() 13 | action = String() 14 | arguments = Map(String()) 15 | observation = String() 16 | user = String() # User context for the step 17 | 18 | class AgentRequest(Record): 19 | question = String() 20 | state = String() 21 | group = Array(String()) 22 | history = Array(AgentStep()) 23 | user = String() # User context for multi-tenancy 24 | streaming = Boolean() # NEW: Enable streaming response delivery (default false) 25 | 26 | class AgentResponse(Record): 27 | # Streaming-first design 28 | chunk_type = String() # "thought", "action", "observation", "answer", "error" 29 | content = String() # The actual content (interpretation depends on chunk_type) 30 | end_of_message = Boolean() # Current chunk type (thought/action/etc.) is complete 31 | end_of_dialog = Boolean() # Entire agent dialog is complete 32 | 33 | # Legacy fields (deprecated but kept for backward compatibility) 34 | answer = String() 35 | error = Error() 36 | thought = String() 37 | observation = String() 38 | 39 | ############################################################################ 40 | 41 | -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/list_config_items.py: -------------------------------------------------------------------------------- 1 | """ 2 | Lists configuration items for a specified type 3 | """ 4 | 5 | import argparse 6 | import os 7 | import json 8 | from trustgraph.api import Api 9 | 10 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 11 | 12 | def list_config_items(url, config_type, format_type): 13 | 14 | api = Api(url).config() 15 | 16 | keys = api.list(config_type) 17 | 18 | if format_type == "json": 19 | print(json.dumps(keys)) 20 | else: 21 | for key in keys: 22 | print(key) 23 | 24 | def main(): 25 | 26 | parser = argparse.ArgumentParser( 27 | prog='tg-list-config-items', 28 | description=__doc__, 29 | ) 30 | 31 | parser.add_argument( 32 | '--type', 33 | required=True, 34 | help='Configuration type to list', 35 | ) 36 | 37 | parser.add_argument( 38 | '--format', 39 | choices=['text', 'json'], 40 | default='text', 41 | help='Output format (default: text)', 42 | ) 43 | 44 | parser.add_argument( 45 | '-u', '--api-url', 46 | default=default_url, 47 | help=f'API URL (default: {default_url})', 48 | ) 49 | 50 | args = parser.parse_args() 51 | 52 | try: 53 | 54 | list_config_items( 55 | url=args.api_url, 56 | config_type=args.type, 57 | format_type=args.format, 58 | ) 59 | 60 | except Exception as e: 61 | 62 | print("Exception:", e, flush=True) 63 | 64 | if __name__ == "__main__": 65 | main() -------------------------------------------------------------------------------- /trustgraph-cli/trustgraph/cli/stop_library_processing.py: -------------------------------------------------------------------------------- 1 | """ 2 | Removes a library document processing record. This is just a record of 3 | procesing, it doesn't stop in-flight processing at the moment. 4 | """ 5 | 6 | import argparse 7 | import os 8 | import tabulate 9 | from trustgraph.api import Api, ConfigKey 10 | import json 11 | 12 | default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') 13 | default_user = "trustgraph" 14 | 15 | def stop_processing( 16 | url, user, id 17 | ): 18 | 19 | api = Api(url).library() 20 | 21 | api.stop_processing(user = user, id = id) 22 | 23 | def main(): 24 | 25 | parser = argparse.ArgumentParser( 26 | prog='tg-stop-library-processing', 27 | description=__doc__, 28 | ) 29 | 30 | parser.add_argument( 31 | '-u', '--api-url', 32 | default=default_url, 33 | help=f'API URL (default: {default_url})', 34 | ) 35 | 36 | parser.add_argument( 37 | '-U', '--user', 38 | default=default_user, 39 | help=f'User ID (default: {default_user})' 40 | ) 41 | 42 | parser.add_argument( 43 | '--id', '--processing-id', 44 | required=True, 45 | help=f'Processing ID', 46 | ) 47 | 48 | args = parser.parse_args() 49 | 50 | try: 51 | 52 | stop_processing( 53 | url = args.api_url, 54 | user = args.user, 55 | id = args.id, 56 | ) 57 | 58 | except Exception as e: 59 | 60 | print("Exception:", e, flush=True) 61 | 62 | if __name__ == "__main__": 63 | main() -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/clients/graph_rag_client.py: -------------------------------------------------------------------------------- 1 | 2 | import _pulsar 3 | 4 | from .. schema import GraphRagQuery, GraphRagResponse 5 | from .. schema import graph_rag_request_queue, graph_rag_response_queue 6 | from . base import BaseClient 7 | 8 | # Ugly 9 | ERROR=_pulsar.LoggerLevel.Error 10 | WARN=_pulsar.LoggerLevel.Warn 11 | INFO=_pulsar.LoggerLevel.Info 12 | DEBUG=_pulsar.LoggerLevel.Debug 13 | 14 | class GraphRagClient(BaseClient): 15 | 16 | def __init__( 17 | self, 18 | log_level=ERROR, 19 | subscriber=None, 20 | input_queue=None, 21 | output_queue=None, 22 | pulsar_host="pulsar://pulsar:6650", 23 | pulsar_api_key=None, 24 | ): 25 | 26 | if input_queue == None: 27 | input_queue = graph_rag_request_queue 28 | 29 | if output_queue == None: 30 | output_queue = graph_rag_response_queue 31 | 32 | super(GraphRagClient, self).__init__( 33 | log_level=log_level, 34 | subscriber=subscriber, 35 | input_queue=input_queue, 36 | output_queue=output_queue, 37 | pulsar_host=pulsar_host, 38 | pulsar_api_key=pulsar_api_key, 39 | input_schema=GraphRagQuery, 40 | output_schema=GraphRagResponse, 41 | ) 42 | 43 | def request( 44 | self, query, user="trustgraph", collection="default", 45 | timeout=500 46 | ): 47 | 48 | return self.call( 49 | user=user, collection=collection, query=query, timeout=timeout 50 | ).response 51 | 52 | -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/messaging/translators/base.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | from typing import Dict, Any, Tuple 3 | from pulsar.schema import Record 4 | 5 | 6 | class Translator(ABC): 7 | """Base class for bidirectional Pulsar ↔ dict translation""" 8 | 9 | @abstractmethod 10 | def to_pulsar(self, data: Dict[str, Any]) -> Record: 11 | """Convert dict to Pulsar schema object""" 12 | pass 13 | 14 | @abstractmethod 15 | def from_pulsar(self, obj: Record) -> Dict[str, Any]: 16 | """Convert Pulsar schema object to dict""" 17 | pass 18 | 19 | 20 | class MessageTranslator(Translator): 21 | """For complete request/response message translation""" 22 | 23 | def from_response_with_completion(self, obj: Record) -> Tuple[Dict[str, Any], bool]: 24 | """Returns (response_dict, is_final) - for streaming responses""" 25 | return self.from_pulsar(obj), True 26 | 27 | 28 | class SendTranslator(Translator): 29 | """For fire-and-forget send operations (like ServiceSender)""" 30 | 31 | def from_pulsar(self, obj: Record) -> Dict[str, Any]: 32 | """Usually not needed for send-only operations""" 33 | raise NotImplementedError("Send translators typically don't need from_pulsar") 34 | 35 | 36 | def handle_optional_fields(obj: Record, fields: list) -> Dict[str, Any]: 37 | """Helper to extract optional fields from Pulsar object""" 38 | result = {} 39 | for field in fields: 40 | value = getattr(obj, field, None) 41 | if value is not None: 42 | result[field] = value 43 | return result -------------------------------------------------------------------------------- /trustgraph-base/trustgraph/schema/services/storage.py: -------------------------------------------------------------------------------- 1 | from pulsar.schema import Record, String 2 | 3 | from ..core.primitives import Error 4 | from ..core.topic import topic 5 | 6 | ############################################################################ 7 | 8 | # Storage management operations 9 | 10 | class StorageManagementRequest(Record): 11 | """Request for storage management operations sent to store processors""" 12 | operation = String() # e.g., "delete-collection" 13 | user = String() 14 | collection = String() 15 | 16 | class StorageManagementResponse(Record): 17 | """Response from storage processors for management operations""" 18 | error = Error() # Only populated if there's an error, if null success 19 | 20 | ############################################################################ 21 | 22 | # Storage management topics 23 | 24 | # Topics for sending collection management requests to different storage types 25 | vector_storage_management_topic = topic( 26 | 'vector-storage-management', kind='non-persistent', namespace='request' 27 | ) 28 | 29 | object_storage_management_topic = topic( 30 | 'object-storage-management', kind='non-persistent', namespace='request' 31 | ) 32 | 33 | triples_storage_management_topic = topic( 34 | 'triples-storage-management', kind='non-persistent', namespace='request' 35 | ) 36 | 37 | # Topic for receiving responses from storage processors 38 | storage_management_response_topic = topic( 39 | 'storage-management', kind='non-persistent', namespace='response' 40 | ) 41 | 42 | ############################################################################ 43 | --------------------------------------------------------------------------------