File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed
Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 1616 username = os .environ .get ("MEMGRAPH_USERNAME" , "memgraph" ),
1717 password = os .environ .get ("MEMGRAPH_PASSWORD" , "memgraph" ),
1818)
19+ db .connect ()
1920
2021loader = WebLoader ("http://localhost:4000/en/enterprise-cloud@latest/copilot" )
2122embedder = TextEmbedding3Small ()
@@ -39,6 +40,8 @@ async def main():
3940 vectors = []
4041 await embedder .process_chunks (chunks , callback = lambda v : vectors .append (v ))
4142 store (source , doc , chunks , vectors )
43+
44+ db .close ()
4245
4346
4447if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -43,12 +43,6 @@ def __init__(
4343 self ._conn = None
4444 self ._cur = None
4545
46- try :
47- self .connect (** kwargs )
48- except Exception as e :
49- print (f"Connection error: { str (e )} " )
50- raise ConnectionError (f"Failed to connect to Memgraph at { host } :{ port } : { str (e )} " ) from e
51-
5246 def connect (self , * args , ** kwargs ) -> None :
5347 raise ConnectionError ("Not implemented" )
5448
@@ -57,7 +51,13 @@ def close(self) -> None:
5751 self ._conn .close ()
5852
5953 # Context-manager support
60- def __enter__ (self ) -> GraphClient :
54+ def __enter__ (self , * args , ** kwargs ) -> GraphClient :
55+ try :
56+ self .connect (** kwargs )
57+ except Exception as e :
58+ print (f"Connection error: { str (e )} " )
59+ raise ConnectionError (f"Failed to connect to Memgraph at { self .host } :{ self .port } : { str (e )} " ) from e
60+
6161 return self
6262
6363 def __exit__ (self , exc_type , exc , tb ) -> None :
You can’t perform that action at this time.
0 commit comments