Generative AI Engineering Lab
A working reference set for the primitives agent systems are actually made of — graph-structured workflows, retrieval strategies, vector stores and schema-constrained model output.
- Python
- LangGraph
- LangChain
- FAISS
- Chroma
- Pydantic
System schematic
Scope note — Presented as an engineering lab and reference implementation set rather than as a shipped product.
Overview
This is a lab, not a product, and it is presented as one. It contains runnable implementations of the pieces that agent and retrieval systems are assembled from: LangGraph workflows in four control-flow shapes, LangChain composition patterns, two retriever strategies that address distinct retrieval failures, two vector store backends, and two approaches to constraining model output to a schema.
Problem
Most published agent code is a single prompt loop. That works in a demo and falls apart in production, because real workflows branch, run steps concurrently, and need to produce output that downstream code can rely on.
The gap is rarely the model. It is control flow, retrieval quality and output contracts — three things that have to be understood at the level of implementation rather than the level of a diagram.
Business context
When an AI feature underperforms, the cause is usually structural: the wrong chunks were retrieved, a step that should have branched did not, or a free-text response was parsed with a regular expression that broke on the first unusual answer.
Being able to reach for the right primitive — a conditional graph, a multi-query retriever, a schema-constrained response — is what separates diagnosing those failures from guessing at prompt wording.
Solution
Workflow topology — sequential graphs for pipelines, parallel graphs for independent work that should not run serially, and conditional graphs for routing on state. Each is implemented rather than described.
Retrieval strategies — a multi-query retriever that reformulates a question into several phrasings to widen recall when a user's wording does not match the corpus, and a contextual compression retriever that strips irrelevant passages from retrieved documents before they consume context budget. They fix opposite problems: one raises recall, the other raises precision.
Storage — FAISS and Chroma implemented side by side, with document loaders and embedding models, so the trade-off between an in-process index and a persistent store is a measured choice rather than a default.
Output contracts — Pydantic models and TypedDict schemas that make a model return parseable, validated structures instead of prose that downstream code has to guess at.
Architecture
Control flow
Sequential graph
Ordered pipeline
Parallel graph
Concurrent branches
Conditional graph
Routing on state
Retrieval
Multi-query
Reformulate → widen recall
Contextual compression
Prune → raise precision
Storage
FAISS
In-process index
Chroma
Persistent store
Document loaders
Directory · text
Model layer
Chat models
Hosted + Hugging Face
Embedding models
Vectorisation
Contracts
Pydantic schema
Validated structured output
TypedDict
Lightweight shape
AI workflow
State moves through a graph rather than through a single prompt. Each node owns one transformation, which makes a failing step identifiable instead of a whole prompt being suspect.
Retrieval is treated as a tunable component with its own quality problem, not as a lookup that either works or does not. Recall and precision are addressed by different strategies, deliberately.
Model output crossing into application code passes through a schema. A response that does not validate fails at the boundary rather than propagating a malformed value.
Implementation
Workflow topologies are implemented as LangGraph notebooks so state transitions can be inspected step by step rather than reasoned about from a diagram.
Chains, loaders, models, retrievers, vector stores and structured-output approaches are organised as small standalone modules, each isolating one concept so it can be swapped or compared directly.
Both vector backends are implemented against the same interface, so switching between an in-process index and a persistent store is a configuration change rather than a rewrite.
Engineering challenges
Recall and precision pull in opposite directions
Widening a query improves the chance of finding the right passage and simultaneously admits more noise. Compressing retrieved documents removes noise and can discard something needed. Having both implemented makes it possible to choose per corpus instead of assuming one setting is universally correct.
Free-text output is not an interface
Parsing prose is brittle by construction. Schema-constrained output moves the failure from a silent misparse deep in application code to an explicit validation error at the boundary.
Serial execution of independent steps
Steps with no data dependency between them do not need to run in sequence, and in a latency-sensitive path they must not. Expressing them as parallel branches in the graph makes the independence explicit rather than accidental.
Key decisions
- Graph-structured workflows over a prompt loop
- Explicit state and explicit transitions are debuggable. A loop that hides its control flow inside a prompt is not.
- Two retrievers rather than one default
- Retrieval failures have distinct causes. Keeping a strategy for each means diagnosing the cause instead of blindly reranking.
- Schemas at every model boundary
- It converts an entire class of runtime parsing bugs into validation errors that surface immediately.
Results
No production metrics are published for this project yet. I would rather show nothing here than a number I cannot stand behind — the architecture and the decisions above are the part worth reviewing.
Technology
Orchestration
- LangGraph
- Sequential / parallel / conditional graphs
Composition
- LangChain
- Chains
- Document loaders
Retrieval
- Multi-query retriever
- Contextual compression retriever
Vector stores
- FAISS
- Chroma
- Embedding models
Contracts
- Pydantic
- TypedDict
- Structured output
Links
Contact
Have an AI product or workflow worth building?
Send me the problem — not the spec. If it’s a fit I’ll tell you how I’d approach it; if it isn’t, I’ll say so.
Faisalabad, Pakistan · PKT (UTC+5) · Working remotely