Spaces:
Runtime error
Runtime error
Download core/graph_engine.py from derangedsaturnian/workflow-agent: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/derangedsaturnian/workflow-agent/resolve/main/core/graph_engine.py
- Command line
-
hf download hf://spaces/derangedsaturnian/workflow-agent/core/graph_engine.py
-
curl -L -o graph_engine.py https://huggingface.co/spaces/derangedsaturnian/workflow-agent/resolve/main/core/graph_engine.py
1.51 kB
| #from llama_index.core import KnowledgeGraphIndex,StorageContext | |
| from llama_index.core import StorageContext | |
| #from llama_index.core.graph_stores import SimpleGraphStore | |
| from llama_index.core import VectorStoreIndex | |
| from llama_index.vector_stores.postgres import PGVectorStore | |
| import psycopg2 | |
| import os | |
| def build_graph_idx(docs,table_name): | |
| #graph_store=SimpleGraphStore() | |
| #storage_context=StorageContext.from_defaults(graph_store=graph_store) | |
| #idx=KnowledgeGraphIndex.from_documents(docs,max_triplets_per_chunk=3,storage_context=storage_context,include_embeddings=True) | |
| for doc in docs: | |
| if doc.get_content(): | |
| clean_text=doc.get_content().replace("\x00","") | |
| doc.set_content(clean_text) | |
| user=os.getenv("DB_USER") | |
| password=os.getenv("DB_PWD") | |
| host=os.getenv("DB_HOST") | |
| port=os.getenv("DB_PORT", "6543") | |
| dbname=os.getenv("DB_NAME", "postgres") | |
| conn_str=f"postgresql://{user}:{password}@{host}:{port}/{dbname}" | |
| vector_store=PGVectorStore( | |
| connection_string=conn_str, | |
| async_connection_string=conn_str.replace("postgresql://", "postgresql+asyncpg://"), | |
| table_name=table_name, | |
| embed_dim=384, | |
| create_engine_kwargs={"connect_args": {"sslmode": "require"}} | |
| ) | |
| storage_context=StorageContext.from_defaults(vector_store=vector_store) | |
| idx=VectorStoreIndex.from_documents(docs,storage_context=storage_context) | |
| print(f"Successfully pushed {len(docs)} docs to {table_name}") | |
| return idx |