Bird
Raised Fist0
Agentic AIml~20 mins

Memory retrieval strategies in Agentic AI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Memory Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does a key-value memory network retrieve information?

In a key-value memory network, what is the main step used to retrieve the correct value from memory?

AMatching the input query with keys to find the most relevant value
BRandomly selecting a value from memory without using the input
CUsing the last stored value regardless of the query
DSorting all values and returning the first one
Attempts:
2 left
💡 Hint

Think about how the network finds the right information based on the input.

Predict Output
intermediate
2:00remaining
Output of memory attention weights calculation

What is the output of the following code that calculates attention weights over memory keys?

Agentic AI
import numpy as np
query = np.array([1, 0])
keys = np.array([[1, 0], [0, 1], [1, 1]])
scores = keys @ query
weights = np.exp(scores) / np.sum(np.exp(scores))
print(weights)
A[1. 0. 0.]
B[0.33333333 0.33333333 0.33333333]
C[0.5 0.5 0.0]
D[0.42214066 0.1553624 0.42214066]
Attempts:
2 left
💡 Hint

Check how the dot product scores are computed and then converted to probabilities.

Hyperparameter
advanced
2:00remaining
Choosing the right memory size for retrieval accuracy

When increasing the size of an external memory in a retrieval model, which effect is most likely to occur if the memory size is too large without proper regularization?

AThe model may retrieve irrelevant information, reducing accuracy
BThe model will always improve accuracy with larger memory
CThe model will ignore the memory and rely only on input features
DThe model will crash due to memory overflow errors
Attempts:
2 left
💡 Hint

Think about how too much information can confuse retrieval.

🔧 Debug
advanced
2:00remaining
Identify the error in memory retrieval code snippet

What error will the following code raise when trying to retrieve a value from memory?

Agentic AI
memory = {'apple': 'fruit', 'carrot': 'vegetable'}
query = 'banana'
value = memory[query]
print(value)
ATypeError
BKeyError
CValueError
DNo error, prints 'fruit'
Attempts:
2 left
💡 Hint

What happens if you try to access a dictionary key that does not exist?

Model Choice
expert
3:00remaining
Best memory retrieval model for long-term context in dialogue systems

Which model architecture is best suited for retrieving relevant long-term context in a dialogue system with very large memory?

AFeedforward neural network with fixed-size input
BSimple RNN without external memory
CDifferentiable Neural Computer (DNC) with content-based addressing
DConvolutional Neural Network (CNN) for image classification
Attempts:
2 left
💡 Hint

Consider models designed to read and write to external memory with flexible addressing.

Practice

(1/5)
1. What is the main purpose of memory retrieval strategies in agentic AI?
easy
A. To find stored information quickly and accurately
B. To create new data from scratch
C. To delete old information permanently
D. To slow down the AI's response time

Solution

  1. Step 1: Understand the role of memory retrieval

    Memory retrieval strategies are designed to help AI find information it has stored before.
  2. Step 2: Identify the main goal

    The goal is to do this quickly and accurately so the AI can respond well.
  3. Final Answer:

    To find stored information quickly and accurately -> Option A
  4. Quick Check:

    Memory retrieval = find info fast [OK]
Hint: Memory retrieval means finding stored info fast [OK]
Common Mistakes:
  • Confusing retrieval with data creation
  • Thinking retrieval deletes data
  • Assuming retrieval slows AI down
2. Which of the following is the correct way to check if a memory item matches a query in Python?
easy
A. if memory_item === query:
B. if memory_item = query:
C. if memory_item == query:
D. if memory_item != query:

Solution

  1. Step 1: Recall Python comparison syntax

    In Python, '==' checks if two values are equal.
  2. Step 2: Identify correct equality check

    '=' is assignment, '===' is not valid in Python, '!=' means not equal.
  3. Final Answer:

    if memory_item == query: -> Option C
  4. Quick Check:

    Equality check in Python = '==' [OK]
Hint: Use '==' to compare values in Python [OK]
Common Mistakes:
  • Using '=' instead of '==' for comparison
  • Using '===' which is JavaScript syntax
  • Confusing '!=' with equality check
3. Given the code below, what will be the output?
memory = ['apple', 'banana', 'cherry']
query = 'banana'
result = None
for item in memory:
    if item == query:
        result = item
        break
print(result)
medium
A. None
B. Error
C. 'apple'
D. 'banana'

Solution

  1. Step 1: Loop through memory list

    The loop checks each item: 'apple', then 'banana', then 'cherry'.
  2. Step 2: Check for match and break

    When 'banana' matches the query, result is set to 'banana' and loop stops.
  3. Final Answer:

    'banana' -> Option D
  4. Quick Check:

    Loop finds 'banana' and stops [OK]
Hint: Loop breaks on first match, returns that item [OK]
Common Mistakes:
  • Assuming result stays None
  • Thinking loop continues after match
  • Confusing output with first list item
4. What is wrong with this memory retrieval code snippet?
memory = []
query = 'orange'
for item in memory:
    if item == query:
        print('Found')
    else:
        print('Not found')
medium
A. It prints 'Not found' multiple times incorrectly
B. It never prints anything if memory is empty
C. It causes a syntax error due to missing colon
D. It crashes because query is not defined

Solution

  1. Step 1: Analyze empty memory list

    The for loop does not run at all if memory is empty.
  2. Step 2: Check output behavior

    Since loop never runs, no print happens, so no indication of 'Not found'.
  3. Final Answer:

    It never prints anything if memory is empty -> Option B
  4. Quick Check:

    Empty list means no loop runs [OK]
Hint: Empty memory means loop skips, no output printed [OK]
Common Mistakes:
  • Thinking 'Not found' prints once automatically
  • Assuming syntax error without checking code
  • Believing query is undefined
5. You want to improve a memory retrieval function to return 'Not found' if no match exists, even when memory is empty. Which code change achieves this best?
def retrieve(memory, query):
    for item in memory:
        if item == query:
            return item
    # What to add here?
hard
A. return 'Not found' after the loop
B. print('Not found') inside the loop
C. return None inside the loop
D. raise Exception('Not found') inside the loop

Solution

  1. Step 1: Understand loop behavior

    If no item matches, loop finishes without returning.
  2. Step 2: Add return after loop

    Returning 'Not found' after loop ensures function always returns a value.
  3. Final Answer:

    return 'Not found' after the loop -> Option A
  4. Quick Check:

    Return after loop handles no matches [OK]
Hint: Return 'Not found' after loop to handle no matches [OK]
Common Mistakes:
  • Putting return inside loop causing premature exit
  • Using print instead of return
  • Raising exception unnecessarily