LangChain (YT style)LangChain 1.4 · Python 3.12+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
46 small wins to finish your pathNext lesson →

Semantic search in long-term memory

Semantic search in the store finds saved items by meaning, not exact words, by giving the store an embedding index and searching it with a query.

Last updated: 27 Sep, 2026 · LangChain 1.4

The store lesson looked items up by key. When you do not know the key, you want the items closest in meaning to a question. That needs an embedding index. An embedding is a list of numbers that stands for a piece of text, made so that texts with similar meaning get similar numbers.

Giving the store an embedding index

Pass index with an embed function and its dims, the number of values in each embedding. The store embeds each saved value so it can compare by meaning. The embed here is a two-number stand-in, so the matching is easy to follow. Save some items, then call search with a query: the store returns the closest ones, not an exact-key match.

Example
from langgraph.store.memory import InMemoryStore

def embed(texts):
    # a tiny stand-in embedding: [mentions refund, mentions ship]
    return [[float("refund" in t.lower()), float("ship" in t.lower())] for t in texts]

store = InMemoryStore(index={"embed": embed, "dims": 2})
store.put(("faqs",), "a", {"text": "Refunds take 5 working days."})
store.put(("faqs",), "b", {"text": "Orders ship within 2 days."})

hits = store.search(("faqs",), query="how long for a refund", limit=1)
print(hits[0].value["text"])

How the query matched

  • The query mentioned a refund, so its embedding was close to the refund item.
  • search ranked the items and returned the nearest one, not an exact key.
  • A real embedding model replaces the stand-in; the call shape is the same.
  • In an agent, a tool calls runtime.store.search(("faqs",), query=question, limit=1) the same way lookup_order called runtime.store.get in Memory that outlives the conversation.
get by keysearch by query
You needThe exact keyOnly a question
MatchesOne itemThe closest items by meaning
SetupNoneAn embedding index

When to search by meaning

  • Recalling the memories relevant to what a user asked.
  • Finding a saved fact when you do not know its key.
  • Ranking many notes by how close they are to a question.
Watch out. Search quality is only as good as the embedding. A weak or mismatched embedding model returns the wrong items, and no amount of ranking fixes that.
Try it yourself
  • Add a third item and a query that should match it.
  • Raise limit to 2 and read both hits in order.
  • Add a third number for the word "cancel" to embed, set dims to 3, save a cancellation answer and search for it.

You understood something today that you didn't yesterday.