new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

LangChain · LangGraph · all subjects

memory/semantic-search

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Semantic search with embeddings in stores

Stores support semantic search by configuring with an embedding model. Configure the store with index containing: embed (embedding provider), dims (embedding dimensions), and fields (fields to embed). Use store.search with a query parameter to find memories based on meaning rather than exact matches.

Semantic search configuration example

To enable semantic search in InMemoryStore, configure it as: store = InMemoryStore(index={'embed': init_embeddings('openai:text-embedding-3-small'), 'dims': 1536, 'fields': ['food_preference', '$']}) where fields can include specific field names or '$' to embed all fields.

Control embedding per field in store.put

Control which parts of memories get embedded by specifying the index parameter when storing memories. Use store.put with index=['field_name'] to only embed specific fields, or index=False to store without embedding (still retrievable but not searchable).

Search memories from a node using runtime.store.asearch

From a node, search memories using: await runtime.store.asearch(namespace, query=state['messages'][-1].content, limit=3). This performs semantic search on memories in the namespace based on the query string.

Semantic search implementation for custom backends

If a custom store backend supports vector search, implement the query parameter on asearch: accept query as str or None, embed it when not None, and rank results by cosine similarity. Include a score field on each Item when query is provided. If backend does not support vector search, raise NotImplementedError when query is passed.

Store semantic search with embeddings

Enable semantic search in stores by providing an embeddings index. For InMemoryStore, PostgresStore, and OracleStore, pass index={"embed": embeddings, "dims": 1536}. Allows searching store items by semantic similarity via store.search(namespace, query=text, limit=n).

Example: InMemoryStore with semantic search

Example showing InMemoryStore with OpenAI embeddings for semantic search. Demonstrates putting items in store and searching them by semantic similarity. Not suitable for production.

Give your agent this brain