Skip to content

Commit

Permalink
feat: add FastAPI lifespan and healthcheck endpoint (#144)
Browse files Browse the repository at this point in the history
* chore: Add healthcheck endpoint + build indexes and constraints on svc startup

* chore: Bring back driver close call
  • Loading branch information
paul-paliychuk committed Sep 23, 2024
1 parent 5d2121e commit 2fc1b00
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion graphiti_core/graphiti.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def close(self):
# Use graphiti...
finally:
graphiti.close()
self.driver.close()
"""
self.driver.close()

async def build_indices_and_constraints(self):
"""
Expand Down
23 changes: 19 additions & 4 deletions server/graph_service/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
from contextlib import asynccontextmanager

from fastapi import FastAPI
from fastapi.responses import JSONResponse

from graph_service.config import get_settings
from graph_service.routers import ingest, retrieve
from graph_service.zep_graphiti import initialize_graphiti


@asynccontextmanager
async def lifespan(_: FastAPI):
settings = get_settings()
await initialize_graphiti(settings)
yield
# Shutdown
# No need to close Graphiti here, as it's handled per-request


app = FastAPI()
app = FastAPI(lifespan=lifespan)


app.include_router(retrieve.router)
app.include_router(ingest.router)


@app.get('/')
def read_root():
return {'Hello': 'World'}
@app.get('/healthcheck')
async def healthcheck():
return JSONResponse(content={'status': 'healthy'}, status_code=200)
9 changes: 9 additions & 0 deletions server/graph_service/zep_graphiti.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ async def get_graphiti(settings: ZepEnvDep):
client.close()


async def initialize_graphiti(settings: ZepEnvDep):
client = ZepGraphiti(
uri=settings.neo4j_uri,
user=settings.neo4j_user,
password=settings.neo4j_password,
)
await client.build_indices_and_constraints()


def get_fact_result_from_edge(edge: EntityEdge):
return FactResult(
uuid=edge.uuid,
Expand Down

0 comments on commit 2fc1b00

Please sign in to comment.