                





==========================================

AI COST OPTIMIZATION (VERY IMPORTANT)

==========================================



The DeepSeek API is expensive compared to traditional backend logic.



The system MUST minimize AI token usage while still providing an intelligent experience.



Design every AI feature with an AI-first mindset but a cost-first implementation.



Never call DeepSeek if the request can be answered using existing application logic.



DeepSeek should only be used when absolutely necessary.



==========================================

AI DECISION ENGINE

==========================================



Create an AI Gateway that decides whether an AI call is necessary.



Flow



User Request



↓



AI Decision Engine



↓



Can traditional backend solve this?



↓



YES



↓



Use Database + Search Engine



↓



NO



↓



Call DeepSeek



Only the AI Gateway may call DeepSeek.



==========================================

RULE 1

DATABASE BEFORE AI

==========================================



If a user searches



"Samsung"



Never use AI.



Search MySQL.



If user filters



Phones under ₦200,000



Never use AI.



Use SQL.



If user sorts



Newest



Cheapest



Nearest



Never use AI.



==========================================

RULE 2

USE AI ONLY FOR NATURAL LANGUAGE

==========================================



Examples requiring AI



"I need a phone with a strong battery."



"I just had a baby."



"I'm getting married."



"I need school items."



AI converts these into structured filters only.



Example output



Category:

Phones



Battery:

Large



Budget:

300000



Brand:

Any



After extraction, search the database using SQL.



Never ask DeepSeek to search products directly.



DeepSeek only extracts user intent.



==========================================

RULE 3

LIMIT PROMPT SIZE

==========================================



Never send the entire product database to DeepSeek.



Never send long conversations.



Only send:



Current user message



Last two conversation messages



Small system prompt



Maximum 1KB context whenever possible.



==========================================

RULE 4

CACHE AI RESPONSES

==========================================



Create AI cache table.



If users ask similar questions



"Best phones under ₦200k"



Reuse cached AI interpretation.



Do not call DeepSeek again.



Cache duration configurable.



==========================================

RULE 5

PROMPT TEMPLATES

==========================================



Store prompts centrally.



Reuse prompts.



Never dynamically generate huge prompts.



==========================================

RULE 6

PREPROCESS BEFORE AI

==========================================



Normalize user input.



Example



"phone"



"phones"



"mobile"



"smartphone"



Convert into standardized keywords before AI.



==========================================

RULE 7

HYBRID SEARCH

==========================================



Use database search first.



Only if confidence is low should AI assist.



Priority



SQL



↓



Full-text search



↓



Synonym search



↓



AI



==========================================

RULE 8

SCAN TO SELL

==========================================



For Scan to Sell



Image analysis should happen once.



Store extracted information.



If seller edits listing later



Never call AI again unless images change.



==========================================

RULE 9

PRODUCT COMPARISON

==========================================



Never ask AI for specifications.



Read specifications directly from database.



Use AI only to summarize.



==========================================

RULE 10

SELLER ANALYTICS

==========================================



Never use AI to calculate sales.



Use SQL.



Use AI only for short recommendations.



Example



SQL returns



Sales down 35%



AI simply says



"Consider running a promotion."



==========================================

RULE 11

MARKET TRENDS

==========================================



Trending products



Trending searches



Popular locations



Top sellers



Top categories



Must all be calculated using SQL aggregation.



Never use AI.



==========================================

RULE 12

REQUEST CENTER

==========================================



When buyer posts request



Run simple grammar correction locally if possible.



Only use AI when user explicitly requests:



"Improve my request"



or



when request quality score is below threshold.



==========================================

RULE 13

SHOPPING ASSISTANT

==========================================



Conversation memory should store structured JSON instead of long chat history.



Example



{

 budget:300000,

 category:"Phone",

 color:"Black",

 location:"Lagos"

}



Only send this JSON to AI.



Never send the whole conversation.



==========================================

RULE 14

VOICE SHOPPING

==========================================



Speech



↓



Speech-to-Text



↓



Database Search



↓



AI only if speech is ambiguous.



==========================================

RULE 15

DEAL HUNTER

==========================================



Price alerts



Price tracking



Notifications



Must be database-driven.



Never use AI.



==========================================

RULE 16

WHATSAPP SHOPPING

==========================================



Store conversation state.



Only summarize context every 10 messages.



Never resend full history.



==========================================

RULE 17

TOKEN LIMITER

==========================================



Maximum input tokens configurable.



Maximum output tokens configurable.



Reject excessive prompts.



==========================================

RULE 18

LOW COST MODE

==========================================



Create an application setting



AI Mode



Options



Economy



Balanced



Premium



Economy



Almost everything solved without AI.



Balanced



Normal AI usage.



Premium



Best AI experience.



==========================================

RULE 19

BACKGROUND AI

==========================================



Whenever possible



Generate AI results asynchronously.



Cache them.



Future users reuse the same result.



==========================================

RULE 20

MEASURE AI COST

==========================================



Create AI Analytics.



Track



Tokens used



Money spent



Requests per day



Cache hit rate



Most expensive prompts



Average cost per feature



Admin dashboard should display all AI costs.



==========================================

FINAL GOAL

==========================================



The application should feel AI-powered while reducing DeepSeek API usage by at least 80%.



Use traditional programming wherever possible.



Only use AI where human reasoning is actually needed.



Think of AI as the last tool in the pipeline, not the first.ZELLA BRAIN

                     │

         ┌───────────┼───────────┐

         │           │           │

     Database     Search     AI Router

         │           │           │

     SQL Query   Full-text    DeepSeek

         │           │           │

         └───────Result──────────┘