# maddy-git/group-5-ds-ai-lab-project architecture

> Architecture diagram of the GitHub repository maddy-git/group-5-ds-ai-lab-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maddy-git/group-5-ds-ai-lab-project
- Repository: https://github.com/maddy-git/group-5-ds-ai-lab-project

## Overview

AI Stylist is a conversational fashion assistant combining personalized product recommendations with store-policy and returns answers. A user submits a query through the app; the chat flow handles login and session context, classifies the query, then dispatches product searches to retrieval and reranking or policy questions to policy RAG. Product answers may include image paths. The README also documents Streamlit use and product embedding. Several links reflect only README-level capabilities because their implementation was not excerpted; those are marked unverified where appropriate.

Main entry points: [`code/chat_flow.py`](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/chat_flow.py) (Chat flow), [`code/productRAG/findKBest.py`](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/findKBest.py) (Product search), [`code/productRAG/reranker.py`](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/reranker.py) (Product reranker), [`code/productRAG/get_customer_context.py`](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/get_customer_context.py) (Customer context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_conversation["Conversation"]
  node_ui["Streamlit chat<br/>[chat_ui.py]"]
  node_api["Query API<br/>[app.py]"]
  node_flow["Chat flow<br/>[chat_flow.py]"]
  node_memory["Session memory<br/>[memory.py]"]
  node_context_check["Context checker"]
  node_classifier["Query classifier<br/>[classify_query.py]"]
end

subgraph group_products["Product recommendations"]
  node_customer_context["Customer context"]
  node_product_search["Product search<br/>[findKBest.py]"]
  node_product_prompts["Refinement prompts<br/>[refinePrompts.py]"]
  node_reranker["Product reranker<br/>[reranker.py]"]
  node_rerank_prompts["Reranker prompts<br/>[rerankerPrompts.py]"]
  node_other_prompts["Response prompts<br/>[otherPrompts.py]"]
  node_product_config["Product configuration<br/>[constants.py]"]
  node_image_fetch["Product images<br/>[image_fetcher.py]"]
  node_product_data[("Catalog data")]
  node_customer_data[("Customer datasets")]
  node_transactions[("Transaction data")]
  node_product_evaluation["Product RAG evaluator<br/>[tester.py]"]
end

subgraph group_policy["Policy answers"]
  node_policy_answer["Policy answer chain<br/>[policy_llm.py]"]
  node_policy_retrieval["Policy retrieval<br/>[fetch_response.py]"]
  node_keyword_generation["Keyword generation"]
  node_keyword_prompt["Keyword prompt<br/>[embed_prompt.py]"]
  node_policy_embedding["Policy embedding<br/>[embed_policy_v2.py]"]
end

subgraph group_preparation["Data preparation"]
  node_product_embedding["Product embedding"]
end

node_user(("Shopper"))

node_user -.->|"submits queries"| node_ui
node_user -.->|"submits queries"| node_api
node_api -->|"dispatches query"| node_flow
node_flow -->|"reads and updates"| node_memory
node_flow -->|"checks context"| node_context_check
node_flow -->|"classifies query"| node_classifier
node_flow -->|"loads profile"| node_customer_context
node_flow -->|"searches products"| node_product_search
node_flow -->|"reranks matches"| node_reranker
node_flow -->|"answers policy"| node_policy_answer
node_flow -->|"fetches images"| node_image_fetch
node_customer_context -->|"reads profiles"| node_customer_data
node_customer_context -->|"reads purchases"| node_transactions
node_customer_context -->|"reads purchased items"| node_product_data
node_product_search -->|"searches embeddings"| node_product_data
node_product_search -->|"uses refinement prompt"| node_product_prompts
node_product_search -->|"uses settings"| node_product_config
node_reranker -->|"uses rerank prompt"| node_rerank_prompts
node_reranker -->|"formats response"| node_other_prompts
node_reranker -->|"uses settings"| node_product_config
node_image_fetch -->|"uses image settings"| node_product_config
node_policy_answer -->|"retrieves context"| node_policy_retrieval
node_policy_retrieval -->|"generates keywords"| node_keyword_generation
node_keyword_generation -->|"formats keywords"| node_keyword_prompt
node_product_embedding -.->|"produces embeddings"| node_product_data
node_policy_embedding -->|"uses keyword generation"| node_keyword_generation
node_product_evaluation -->|"evaluates retrieval"| node_product_search
node_product_evaluation -->|"evaluates ranking"| node_reranker

click node_ui "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/chat_ui.py"
click node_api "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/app.py"
click node_flow "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/chat_flow.py"
click node_memory "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/memory.py"
click node_context_check "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/user_context_checker.py"
click node_classifier "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/classify_query.py"
click node_customer_context "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/get_customer_context.py"
click node_product_search "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/findKBest.py"
click node_product_prompts "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/prompts/refinePrompts.py"
click node_reranker "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/reranker.py"
click node_rerank_prompts "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/prompts/rerankerPrompts.py"
click node_other_prompts "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/prompts/otherPrompts.py"
click node_product_config "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/constants.py"
click node_image_fetch "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/image_fetcher.py"
click node_product_data "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/data/cloth_test_set.parquet"
click node_customer_data "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/data/customers_first_3000.csv"
click node_transactions "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/data/transactions_first_3000_customers.csv"
click node_policy_answer "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policy_llm.py"
click node_policy_retrieval "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policyRAG/fetch_response.py"
click node_keyword_generation "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policyRAG/genrate_keywords.py"
click node_keyword_prompt "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policyRAG/embed_prompt.py"
click node_policy_embedding "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policyRAG/embed_policy_v2.py"
click node_product_embedding "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/product_embedder.py"
click node_product_evaluation "https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/tester.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui,node_api,node_flow,node_memory,node_context_check,node_classifier toneBlue
class node_customer_context,node_product_search,node_product_prompts,node_reranker,node_rerank_prompts,node_other_prompts,node_product_config,node_image_fetch,node_product_data,node_customer_data,node_transactions,node_product_evaluation toneAmber
class node_policy_answer,node_policy_retrieval,node_keyword_generation,node_keyword_prompt,node_policy_embedding toneMint
class node_product_embedding toneRose
class node_user toneIndigo
```

## Components

### Conversation

- [Streamlit chat](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/chat_ui.py): `code/chat_ui.py`
- [Query API](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/app.py): `code/app.py`
- [Chat flow](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/chat_flow.py): `code/chat_flow.py`
- [Session memory](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/memory.py): `code/memory.py`
- [Context checker](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/user_context_checker.py): `code/user_context_checker.py`
- [Query classifier](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/classify_query.py): `code/productRAG/classify_query.py`

### Product recommendations

- [Customer context](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/get_customer_context.py): `code/productRAG/get_customer_context.py`
- [Product search](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/findKBest.py): `code/productRAG/findKBest.py`
- [Refinement prompts](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/prompts/refinePrompts.py): `code/productRAG/prompts/refinePrompts.py`
- [Product reranker](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/reranker.py): `code/productRAG/reranker.py`
- [Reranker prompts](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/prompts/rerankerPrompts.py): `code/productRAG/prompts/rerankerPrompts.py`
- [Response prompts](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/prompts/otherPrompts.py): `code/productRAG/prompts/otherPrompts.py`
- [Product configuration](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/constants.py): `code/productRAG/constants.py`
- [Product images](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/image_fetcher.py): `code/productRAG/image_fetcher.py`
- [Catalog data](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/data/cloth_test_set.parquet): `data/cloth_test_set.parquet`
- [Customer datasets](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/data/customers_first_3000.csv): `data/customers_first_3000.csv`
- [Transaction data](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/data/transactions_first_3000_customers.csv): `data/transactions_first_3000_customers.csv`
- [Product RAG evaluator](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/tester.py): `code/productRAG/tester.py`

### Policy answers

- [Policy answer chain](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policy_llm.py): `code/policy_llm.py`
- [Policy retrieval](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policyRAG/fetch_response.py): `code/policyRAG/fetch_response.py`
- [Keyword generation](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policyRAG/genrate_keywords.py): `code/policyRAG/genrate_keywords.py`
- [Keyword prompt](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policyRAG/embed_prompt.py): `code/policyRAG/embed_prompt.py`
- [Policy embedding](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/policyRAG/embed_policy_v2.py): `code/policyRAG/embed_policy_v2.py`

### Data preparation

- [Product embedding](https://github.com/maddy-git/group-5-ds-ai-lab-project/blob/main/code/productRAG/product_embedder.py): `code/productRAG/product_embedder.py`

### Other components

- **Shopper**

## Connections

- Shopper → Streamlit chat: submits queries (evidence: `README.md`)
- Shopper → Query API: submits queries (evidence: `README.md`)
- Query API → Chat flow: dispatches query (evidence: `code/app.py`)
- Chat flow → Session memory: reads and updates (evidence: `code/chat_flow.py`)
- Chat flow → Context checker: checks context (evidence: `code/chat_flow.py`)
- Chat flow → Query classifier: classifies query (evidence: `code/chat_flow.py`)
- Chat flow → Customer context: loads profile (evidence: `code/chat_flow.py`)
- Chat flow → Product search: searches products (evidence: `code/chat_flow.py`)
- Chat flow → Product reranker: reranks matches (evidence: `code/chat_flow.py`)
- Chat flow → Policy answer chain: answers policy (evidence: `code/chat_flow.py`)
- Chat flow → Product images: fetches images (evidence: `code/chat_flow.py`)
- Customer context → Customer datasets: reads profiles (evidence: `code/productRAG/get_customer_context.py`)
- Customer context → Transaction data: reads purchases (evidence: `code/productRAG/get_customer_context.py`)
- Customer context → Catalog data: reads purchased items (evidence: `code/productRAG/get_customer_context.py`)
- Product search → Catalog data: searches embeddings (evidence: `code/productRAG/findKBest.py`)
- Product search → Refinement prompts: uses refinement prompt (evidence: `code/productRAG/findKBest.py`)
- Product search → Product configuration: uses settings (evidence: `code/productRAG/findKBest.py`)
- Product reranker → Reranker prompts: uses rerank prompt (evidence: `code/productRAG/reranker.py`)
- Product reranker → Response prompts: formats response (evidence: `code/productRAG/reranker.py`)
- Product reranker → Product configuration: uses settings (evidence: `code/productRAG/reranker.py`)
- Product images → Product configuration: uses image settings (evidence: `code/productRAG/image_fetcher.py`)
- Policy answer chain → Policy retrieval: retrieves context (evidence: `code/policy_llm.py`)
- Policy retrieval → Keyword generation: generates keywords (evidence: `code/policyRAG/fetch_response.py`)
- Keyword generation → Keyword prompt: formats keywords (evidence: `code/policyRAG/genrate_keywords.py`)
- Product embedding → Catalog data: produces embeddings (evidence: `README.md`)
- Policy embedding → Keyword generation: uses keyword generation (evidence: `code/policyRAG/embed_policy_v2.py`)
- Product RAG evaluator → Product search: evaluates retrieval (evidence: `code/productRAG/tester.py`)
- Product RAG evaluator → Product reranker: evaluates ranking (evidence: `code/productRAG/tester.py`)
