top of page
Search

AI - Design Patterns

  • pbindupriyadarshini
  • Dec 30, 2024
  • 4 min read

As we start to see more Gen AI applications in production several common design patterns are emerging, majority of these patterns are designed to improve the context, because at the end of the day Gen improves based on the context that it gets, so let's look at 8 Gen Patterns that are commonly used when building AI


 

  1. Retrieval Augmented Generation or RAG

 

Rag works by retrieving the most relevant portion of the document and use it as a context to generate the answer. Imagine when you're troubleshooting a steering wheel problem in your car you do not read the entire manual you look only for the portions that are related to the steering wheel. RAG works by having an AI go through massive Digital Library to get bits and pieces of the most relevant information to your query it, then crafts the Snippets into a coherent and informative answer for you.

 



 

  1. One Shot OR Few Shot


Learning this is basically like giving AI a cheat sheet it's like teaching a kid how to solve a math problem by showing them a solve example first you show an example or two of what you're looking for and it follows those example to deliver answers molded in the same style this approach has been proven to work in multiple studies especially with reasoning task.


 

 3. Multi Query

 

Multi-query retriever this design uses AI to rephrase the original question into multiple related questions often giving broader perspective about the original topic. This then leads to finding more relevant context and the context found are then are by relevance. The answer is generated is like asking the AI to expand our original question because we are too lazy to type long questions.


 

  1. Reason Action or the React agent


In this pattern AI plays like a detective agent it examines the clues from the questions and available answers and it decides if it needs to take an action. There are multiple tools available to the agent like searching the web or Consulting Wikipedia Web MD or internal document it decides which among these tools are the most useful for the given question it retrieves information, then use that as additional clue if it needs more information it can use another tool to get more clues once it is satisfied with the clues. It will generate the response to answer the question, based on the clues that it has gathered .

 


 

  1. Knowledge Graph


It is the latest approach towards smarter Gen AI answers. Knowledge Graph represents the concepts in our world entities and the relationships between them. For example by kicking the ball you can have a player in the ball as entity then kick as a relationship between them using this representation. We are able to represent the concepts in the real world in a more meaningful way, as a result the query in our knowledge Graph will return a more realistic representation of the real world thereby making AI generate more accurate answers.


  1. Multi Agent


Multi Agent is another variant of react pattern but having a router or a supervisor that is responsible for invoking another agent or tool. Just like teams in the real world you have a team leader that can orchestrate actions to be performed by every member. In this example the router is a team leader that identifies if research is needed if yes, it instructs the researcher agent to look for answers once results are back the team leader assess, if that data is sufficient if not it will prompt back to the researcher agent to do further research once the team leader is satisfied. It can then ask the Chart Generator agent to produce the desired result. You can imagine this pattern using different types of agent performing different specific tasks.

 



 7. Layered Cache


Layered cash is when you want to optimize all operations by using smaller agents like Microsoft's 53 or Lama 7B, because they are cost efficient but you make them smarter by preparing a set of questions and prompts that users may ask. You can ask a larger model to produce sample questions

and prompts also called synthetic data. then save the answer into a permanent storage a vector store which can access a cash, the smaller model can then reference to this cash when searching for an answer making it smart and efficient at the same time.


 

  1. Red & Blue Team.

 

Tag team of Maker and Checker ensures that the answers are validated before sending back to the user. Blue Team acts as the maker or writer to generate the initial response to the question then the Red Team will check the response against several factors like accuracy, relevancy, toxicity and more. This response is sent back to the writer for correction when the answer passes a check from the Red Team, the answer is finalized and returned back to the user.

 



Those are 8 Gen AI Design Patterns that can guide you, how to build your solution. Just remember it's all about building the perfect context for the Gen AI to generate the perfect answer. You can mix and match all these patterns to build the model that suits your use case hope you enjoyed this reading of Artificially Intelligent.

 
 
 

コメント


bottom of page