NVIDIA / NVIDIA/NeMo-Retriever

[FEA]: Use asynccontextmanager to manage ingest_service life cycle

Open
#969 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
Python
Stars
3k
Forks
349
Avg merge
1d 23h
Merged PRs (30d)
116

Description

Is this a new feature, an improvement, or a change to existing functionality?

New Feature

How would you describe the priority of this feature request

Make RedisIngestService lifecycle management more explicit. It can help with redis warm up connections and gracefully shutdown.

Please provide a clear description of problem this feature solves

RedisIngestService.get_instance() creates (lazy) and stores a global object the first time it’s called. Its life cycle management is implicit: creation, initialization, gracefully shutdown.

Proposal: add LifeSpan in with context manager at app level (main.py)

Benefits:

  • Creates one RedisIngestService per process and stores it as app.state.ingest_service.
  • Attempts graceful shutdown/cleanup on app stop.
Describe the feature, and optionally a solution or implementation and any alternatives

logger = logging.getLogger(name)

.....
@asynccontextmanager
async def lifespan(app: FastAPI):
# Build once per process; app owns the instance
app.state.ingest_service = create_ingest_service()
try:
yield
finally:
svc = getattr(app.state, "ingest_service", None)
if svc is not None:
close = getattr(svc, "close", None)
if callable(close):
try:
maybe = close()
import asyncio
if asyncio.iscoroutine(maybe):
await maybe
except Exception:
logger.exception("Error closing ingest service during shutdown")

.....
app = FastAPI(
title="NV-Ingest Microservice",
description="Service for ingesting heterogenous datatypes",
version="25.6.2",
contact={
"name": "NVIDIA Corporation",
"url": "https://nvidia.com",
},
docs_url="/docs",
)

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in main.py at the FastAPI app construction and trace RedisIngestService.get_instance(), including its initialization and shutdown behavior. Compare that flow with the proposed lifespan context manager and app.state.ingest_service ownership. Done means one service is created per process and cleanup is attempted during app shutdown without breaking startup.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python, redis
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.