SemanticStore
A Store whose search finds the items that a query means, with the vectors of an EmbeddingModel: "what does she eat?" finds "Piscivegetarian: fish, but no meat", which has none of its words. Everything else goes to store as it is.
val embeddings = OpenAiEmbeddingModel(client, apiKey = key)
val store = SemanticStore(SqlDelightStore(driver), embeddings)
graph.invoke(input, GraphConfig(threadId = "plan-7", store = store.within("users", userId)))
// In a node or a tool:
val found = store().search(listOf("memories"), "what does the traveller eat?", limit = 5)How it works:
A vector is made when a search first needs it, not when an item is put: a put calls no model, and an item that other code put into store is found too. A search makes the vectors of the items that have none, in calls of at most 100 texts to embeddings, and one for the query.
The vectors are kept in store, in the namespace VECTORS followed by the namespace of the item, with the item's key. So a store that keeps its items keeps their vectors, and the next search only makes the vector of the query. Do not put items of your own under VECTORS: list leaves that namespace out.
A vector is made again when the value of its item changed, or the EmbeddingModel.id did. A vector whose item was deleted is deleted by the next search that sees all the items of its namespace.
The vector of an item is made from its key and its value, as
"diet: Piscivegetarian".A search looks at the scope items that
listreturns first, the ones changed last, and ranks them by the cosine of their vector and the vector of the query. An item below minScore is left out.
Use it through within as any store. A run with this store gives recall of memoryTools a search by meaning, and a GraphConfig takes it as its store.
Parameters
where the items and their vectors are kept.
makes the vectors.
the lowest cosine, from -1 to 1, of an item that a search returns. The default returns every item, the best first. What a good limit is depends on the model.
how many items a search looks at.