mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 08:26:21 +02:00
* Update schema defs for source -> metadata * Migrate to use metadata part of schema, also add metadata to triples & vecs * Add user/collection metadata to query * Use user/collection in RAG * Write and query working on triples
68 lines
1.4 KiB
Python
Executable file
68 lines
1.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
"""
|
|
Uses the GraphRAG service to answer a query
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
from trustgraph.clients.graph_rag_client import GraphRagClient
|
|
|
|
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
|
|
default_user = 'trustgraph'
|
|
default_collection = 'default'
|
|
|
|
def query(pulsar_host, query, user, collection):
|
|
|
|
rag = GraphRagClient(pulsar_host=pulsar_host)
|
|
resp = rag.request(user=user, collection=collection, query=query)
|
|
print(resp)
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
prog='tg-graph-query-rag',
|
|
description=__doc__,
|
|
)
|
|
|
|
parser.add_argument(
|
|
'-p', '--pulsar-host',
|
|
default=default_pulsar_host,
|
|
help=f'Pulsar host (default: {default_pulsar_host})',
|
|
)
|
|
|
|
parser.add_argument(
|
|
'-q', '--query',
|
|
required=True,
|
|
help=f'Query to execute',
|
|
)
|
|
|
|
parser.add_argument(
|
|
'-u', '--user',
|
|
default=default_user,
|
|
help=f'User ID (default: {default_user})'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'-c', '--collection',
|
|
default=default_collection,
|
|
help=f'Collection ID (default: {default_collection})'
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
|
|
query(
|
|
pulsar_host=args.pulsar_host,
|
|
query=args.query,
|
|
user=args.user,
|
|
collection=args.collection,
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
print("Exception:", e, flush=True)
|
|
|
|
main()
|
|
|