
Context Injection
Managing the context window.
Context Injection
How do you get the retrieved docs into the prompt? By updating the State.
def retrieve(state):
docs = vector_store.search(state["query"])
return {"documents": docs}
def generate(state):
# The 'documents' key is now populated
prompt = f"Context: {state['documents']}..."
return llm(prompt)
This clear separation (retrieving merely populates state; generating reads state) makes the system modular. You can hot-swap the Retriever without touching the Generator.