Imagine you have an AI agent that needs to remember important information from past conversations. How does using a vector store help the agent keep and find this information later?
Think about how the agent finds related information, not just storing raw text.
Vector stores convert information into number arrays (vectors) that capture meaning. This allows the agent to search for memories similar in meaning, enabling effective long-term memory retrieval.
Given the following code snippet using a vector store, what will be the output?
from sklearn.metrics.pairwise import cosine_similarity import numpy as np # Stored vectors representing past memories memory_vectors = np.array([[1, 0], [0, 1], [1, 1]]) # New query vector query_vector = np.array([[0.9, 0.1]]) # Compute similarity scores scores = cosine_similarity(query_vector, memory_vectors) # Find index of most similar memory most_similar_index = np.argmax(scores) print(most_similar_index)
Look at which stored vector is closest to the query vector in direction.
The query vector [0.9, 0.1] is closest to [1, 0] among the stored vectors, so the index 0 is the most similar.
You want to build a long-term memory system for an AI agent that remembers conversations. Which embedding model is best to create vectors that capture semantic meaning for diverse topics?
Think about which model understands word meaning in context.
Transformer-based models like BERT produce embeddings that capture the meaning of words in context, making them ideal for semantic search in long-term memory.
When creating vector embeddings for long-term memory, what is the effect of increasing the vector dimension size?
Consider trade-offs between detail and resource use.
Larger vector dimensions can capture more information but increase computation and storage needs, potentially slowing down similarity searches.
Review the code below. The similarity search returns unexpected results. What is the main issue?
import numpy as np def cosine_similarity(a, b): return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b)) memory_vectors = np.array([[1, 0], [0, 1], [1, 1]]) query_vector = np.array([0.9, 0.1]) scores = [] for vec in memory_vectors: scores.append(cosine_similarity(query_vector, vec)) most_similar_index = np.argmax(scores) print(most_similar_index)
Check how the cosine similarity is computed for each vector.
The cosine_similarity function computes similarity between two 1D vectors correctly. The loop computes similarity for each stored vector. The code returns the correct most similar index.