4040# Configure logging
4141logging .basicConfig (
4242 level = INFO ,
43- format = " %(asctime)s - %(name)s - %(levelname)s - %(message)s" ,
44- datefmt = " %Y-%m-%d %H:%M:%S" ,
43+ format = ' %(asctime)s - %(name)s - %(levelname)s - %(message)s' ,
44+ datefmt = ' %Y-%m-%d %H:%M:%S' ,
4545)
4646logger = logging .getLogger (__name__ )
4747
4848load_dotenv ()
4949
5050# Neo4j connection parameters
5151# Make sure Neo4j Desktop is running with a local DBMS started
52- neo4j_uri = os .environ .get (" NEO4J_URI" , " bolt://localhost:7687" )
53- neo4j_user = os .environ .get (" NEO4J_USER" , " neo4j" )
54- neo4j_password = os .environ .get (" NEO4J_PASSWORD" , " password" )
52+ neo4j_uri = os .environ .get (' NEO4J_URI' , ' bolt://localhost:7687' )
53+ neo4j_user = os .environ .get (' NEO4J_USER' , ' neo4j' )
54+ neo4j_password = os .environ .get (' NEO4J_PASSWORD' , ' password' )
5555
5656# Azure OpenAI connection parameters
57- azure_endpoint = os .environ .get (" AZURE_OPENAI_ENDPOINT" )
58- azure_api_key = os .environ .get (" AZURE_OPENAI_API_KEY" )
59- azure_deployment = os .environ .get (" AZURE_OPENAI_DEPLOYMENT" , " gpt-4.1" )
57+ azure_endpoint = os .environ .get (' AZURE_OPENAI_ENDPOINT' )
58+ azure_api_key = os .environ .get (' AZURE_OPENAI_API_KEY' )
59+ azure_deployment = os .environ .get (' AZURE_OPENAI_DEPLOYMENT' , ' gpt-4.1' )
6060azure_embedding_deployment = os .environ .get (
61- " AZURE_OPENAI_EMBEDDING_DEPLOYMENT" , " text-embedding-3-small"
61+ ' AZURE_OPENAI_EMBEDDING_DEPLOYMENT' , ' text-embedding-3-small'
6262)
6363
6464if not azure_endpoint or not azure_api_key :
65- raise ValueError (" AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_API_KEY must be set" )
65+ raise ValueError (' AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_API_KEY must be set' )
6666
6767
6868async def main ():
@@ -76,7 +76,7 @@ async def main():
7676
7777 # Initialize Azure OpenAI client
7878 azure_client = AsyncOpenAI (
79- base_url = f" { azure_endpoint } /openai/v1/" ,
79+ base_url = f' { azure_endpoint } /openai/v1/' ,
8080 api_key = azure_api_key ,
8181 )
8282
@@ -112,40 +112,40 @@ async def main():
112112 # Episodes list containing both text and JSON episodes
113113 episodes = [
114114 {
115- " content" : " Kamala Harris is the Attorney General of California. She was previously "
116- " the district attorney for San Francisco." ,
117- " type" : EpisodeType .text ,
118- " description" : " podcast transcript" ,
115+ ' content' : ' Kamala Harris is the Attorney General of California. She was previously '
116+ ' the district attorney for San Francisco.' ,
117+ ' type' : EpisodeType .text ,
118+ ' description' : ' podcast transcript' ,
119119 },
120120 {
121- " content" : " As AG, Harris was in office from January 3, 2011 – January 3, 2017" ,
122- " type" : EpisodeType .text ,
123- " description" : " podcast transcript" ,
121+ ' content' : ' As AG, Harris was in office from January 3, 2011 – January 3, 2017' ,
122+ ' type' : EpisodeType .text ,
123+ ' description' : ' podcast transcript' ,
124124 },
125125 {
126- " content" : {
127- " name" : " Gavin Newsom" ,
128- " position" : " Governor" ,
129- " state" : " California" ,
130- " previous_role" : " Lieutenant Governor" ,
131- " previous_location" : " San Francisco" ,
126+ ' content' : {
127+ ' name' : ' Gavin Newsom' ,
128+ ' position' : ' Governor' ,
129+ ' state' : ' California' ,
130+ ' previous_role' : ' Lieutenant Governor' ,
131+ ' previous_location' : ' San Francisco' ,
132132 },
133- " type" : EpisodeType .json ,
134- " description" : " podcast metadata" ,
133+ ' type' : EpisodeType .json ,
134+ ' description' : ' podcast metadata' ,
135135 },
136136 ]
137137
138138 # Add episodes to the graph
139139 for i , episode in enumerate (episodes ):
140140 await graphiti .add_episode (
141- name = f" California Politics { i } " ,
141+ name = f' California Politics { i } ' ,
142142 episode_body = (
143- episode [" content" ]
144- if isinstance (episode [" content" ], str )
145- else json .dumps (episode [" content" ])
143+ episode [' content' ]
144+ if isinstance (episode [' content' ], str )
145+ else json .dumps (episode [' content' ])
146146 ),
147- source = episode [" type" ],
148- source_description = episode [" description" ],
147+ source = episode [' type' ],
148+ source_description = episode [' description' ],
149149 reference_time = datetime .now (timezone .utc ),
150150 )
151151 print (f'Added episode: California Politics { i } ({ episode ["type" ].value } )' )
@@ -161,18 +161,18 @@ async def main():
161161
162162 # Perform a hybrid search combining semantic similarity and BM25 retrieval
163163 print ("\n Searching for: 'Who was the California Attorney General?'" )
164- results = await graphiti .search (" Who was the California Attorney General?" )
164+ results = await graphiti .search (' Who was the California Attorney General?' )
165165
166166 # Print search results
167- print (" \n Search Results:" )
167+ print (' \n Search Results:' )
168168 for result in results :
169- print (f" UUID: { result .uuid } " )
170- print (f" Fact: { result .fact } " )
171- if hasattr (result , " valid_at" ) and result .valid_at :
172- print (f" Valid from: { result .valid_at } " )
173- if hasattr (result , " invalid_at" ) and result .invalid_at :
174- print (f" Valid until: { result .invalid_at } " )
175- print (" ---" )
169+ print (f' UUID: { result .uuid } ' )
170+ print (f' Fact: { result .fact } ' )
171+ if hasattr (result , ' valid_at' ) and result .valid_at :
172+ print (f' Valid from: { result .valid_at } ' )
173+ if hasattr (result , ' invalid_at' ) and result .invalid_at :
174+ print (f' Valid until: { result .invalid_at } ' )
175+ print (' ---' )
176176
177177 #################################################
178178 # CENTER NODE SEARCH
@@ -187,26 +187,26 @@ async def main():
187187 # Get the source node UUID from the top result
188188 center_node_uuid = results [0 ].source_node_uuid
189189
190- print (" \n Reranking search results based on graph distance:" )
191- print (f" Using center node UUID: { center_node_uuid } " )
190+ print (' \n Reranking search results based on graph distance:' )
191+ print (f' Using center node UUID: { center_node_uuid } ' )
192192
193193 reranked_results = await graphiti .search (
194- " Who was the California Attorney General?" ,
194+ ' Who was the California Attorney General?' ,
195195 center_node_uuid = center_node_uuid ,
196196 )
197197
198198 # Print reranked search results
199- print (" \n Reranked Search Results:" )
199+ print (' \n Reranked Search Results:' )
200200 for result in reranked_results :
201- print (f" UUID: { result .uuid } " )
202- print (f" Fact: { result .fact } " )
203- if hasattr (result , " valid_at" ) and result .valid_at :
204- print (f" Valid from: { result .valid_at } " )
205- if hasattr (result , " invalid_at" ) and result .invalid_at :
206- print (f" Valid until: { result .invalid_at } " )
207- print (" ---" )
201+ print (f' UUID: { result .uuid } ' )
202+ print (f' Fact: { result .fact } ' )
203+ if hasattr (result , ' valid_at' ) and result .valid_at :
204+ print (f' Valid from: { result .valid_at } ' )
205+ if hasattr (result , ' invalid_at' ) and result .invalid_at :
206+ print (f' Valid until: { result .invalid_at } ' )
207+ print (' ---' )
208208 else :
209- print (" No results found in the initial search to use as center node." )
209+ print (' No results found in the initial search to use as center node.' )
210210
211211 finally :
212212 #################################################
@@ -218,8 +218,8 @@ async def main():
218218
219219 # Close the connection
220220 await graphiti .close ()
221- print (" \n Connection closed" )
221+ print (' \n Connection closed' )
222222
223223
224- if __name__ == " __main__" :
224+ if __name__ == ' __main__' :
225225 asyncio .run (main ())
0 commit comments