neurotrace.core.vector_memory
¶
neurotrace.core.vector_memory
¶
BaseVectorMemoryAdapter
¶
Bases: ABC
Abstract base class for vector memory storage adapters.
This class defines the interface for storing and retrieving messages using vector embeddings. Implementations should provide concrete methods for adding, searching, and optionally deleting messages from the vector store.
Source code in neurotrace/core/vector_memory.py
add_messages(messages)
abstractmethod
¶
Add a list of messages to the vector memory store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
List[Message]
|
List of Message objects to be added to the vector store. Each message will be embedded and stored. |
required |
Source code in neurotrace/core/vector_memory.py
delete(ids)
abstractmethod
¶
Delete messages from the vector store by their IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
List[str]
|
List of message IDs to be deleted from the store. |
required |
Note
This is an optional operation that might not be supported by all vector store implementations.
Source code in neurotrace/core/vector_memory.py
search(query, k=5)
abstractmethod
¶
Search the vector memory for the most relevant messages.
Performs a similarity search in the vector store using the provided query string. The query will be embedded and compared against stored message embeddings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The search query string. |
required |
k
|
int
|
Maximum number of results to return. Defaults to 5. |
5
|
Returns:
Type | Description |
---|---|
List[Message]
|
List[Message]: List of messages ranked by similarity to the query, limited to k results. |
Source code in neurotrace/core/vector_memory.py
VectorMemoryAdapter
¶
Bases: BaseVectorMemoryAdapter
Concrete implementation of vector memory storage using LangChain components.
This adapter wraps a LangChain-compatible vector store and embedding model to provide vector-based message storage and retrieval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector_store
|
VectorStore
|
LangChain vector store implementation for storing embeddings. |
required |
embedding_model
|
Embeddings
|
LangChain embeddings model for converting text to vectors. |
required |
Source code in neurotrace/core/vector_memory.py
__init__(vector_store)
¶
Vector memory adapter that wraps a LangChain-compatible vector store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector_store
|
VectorStore
|
Any LangChain-compatible vector store. |
required |
embedding_model
|
Embeddings
|
Embedding model to generate embeddings. |
required |
Source code in neurotrace/core/vector_memory.py
add_messages(messages)
¶
Add multiple messages to the vector store.
Converts the messages to LangChain Document format and adds them to the underlying vector store. The documents will be automatically embedded using the configured embedding model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
List[Message]
|
List of messages to be added to the vector store. |
required |
Source code in neurotrace/core/vector_memory.py
delete(ids)
¶
Delete messages from the vector store by their IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
List[str]
|
List of message IDs to be deleted. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the underlying vector store doesn't support deletion operations. |
Source code in neurotrace/core/vector_memory.py
search(query, k=5)
¶
Search for similar messages in the vector store.
Performs a similarity search using the query string. The query is embedded and compared against stored message embeddings to find the most similar messages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The search query string. |
required |
k
|
int
|
Maximum number of results to return. Defaults to 5. |
5
|
Returns:
Type | Description |
---|---|
List[Message]
|
List[Message]: List of messages ranked by similarity to the query, limited to k results. |
Note
TODO: Add support for enhancing the prompt for vector search using LLM.