SemanticTextMemory Class
Class for semantic text memory.
Note: This class is marked as 'experimental' and may change in the future.
Initialize a new instance of SemanticTextMemory.
Constructor
SemanticTextMemory(storage: MemoryStoreBase, embeddings_generator: EmbeddingGeneratorBase)
Parameters
| Name | Description |
|---|---|
|
storage
Required
|
<xref:semantic_kernel.memory.MemoryStoreBase>
The MemoryStoreBase to use for storage. |
|
embeddings_generator
Required
|
<xref:semantic_kernel.memory.EmbeddingGeneratorBase>
The EmbeddingGeneratorBase to use for generating embeddings. |
Methods
| get |
Get information from the memory (calls the memory store's get method). |
| get_collections |
Get the list of collections in the memory (calls the memory store's get_collections method). |
| model_post_init |
This function is meant to behave like a BaseModel method to initialise private attributes. It takes context as an argument since that's what pydantic-core passes when calling it. |
| save_information |
Save information to the memory (calls the memory store's upsert method). |
| save_reference |
Save a reference to the memory (calls the memory store's upsert method). |
| search |
Search the memory (calls the memory store's get_nearest_matches method). |
get
Get information from the memory (calls the memory store's get method).
async get(collection: str, key: str) -> MemoryQueryResult | None
Parameters
| Name | Description |
|---|---|
|
collection
Required
|
The collection to get the information from. |
|
key
Required
|
The key of the information. |
Returns
| Type | Description |
|---|---|
|
The MemoryQueryResult if found, None otherwise. |
get_collections
model_post_init
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that's what pydantic-core passes when calling it.
model_post_init(context: Any, /) -> None
Positional-Only Parameters
| Name | Description |
|---|---|
|
context
Required
|
|
Parameters
| Name | Description |
|---|---|
|
self
Required
|
The BaseModel instance. |
|
context
Required
|
The context. |
save_information
Save information to the memory (calls the memory store's upsert method).
async save_information(collection: str, text: str, id: str, description: str | None = None, additional_metadata: str | None = None, embeddings_kwargs: dict[str, Any] | None = {}) -> None
Parameters
| Name | Description |
|---|---|
|
collection
Required
|
The collection to save the information to. |
|
text
Required
|
The text to save. |
|
id
Required
|
The id of the information. |
|
description
|
<xref:Optional>[str]
The description of the information. Default value: None
|
|
additional_metadata
|
<xref:Optional>[str]
Additional metadata of the information. Default value: None
|
|
embeddings_kwargs
|
The embeddings kwargs of the information. Default value: {}
|
save_reference
Save a reference to the memory (calls the memory store's upsert method).
async save_reference(collection: str, text: str, external_id: str, external_source_name: str, description: str | None = None, additional_metadata: str | None = None, embeddings_kwargs: dict[str, Any] | None = {}) -> None
Parameters
| Name | Description |
|---|---|
|
collection
Required
|
The collection to save the reference to. |
|
text
Required
|
The text to save. |
|
external_id
Required
|
The external id of the reference. |
|
external_source_name
Required
|
The external source name of the reference. |
|
description
|
<xref:Optional>[str]
The description of the reference. Default value: None
|
|
additional_metadata
|
<xref:Optional>[str]
Additional metadata of the reference. Default value: None
|
|
embeddings_kwargs
|
The embeddings kwargs of the reference. Default value: {}
|
search
Search the memory (calls the memory store's get_nearest_matches method).
async search(collection: str, query: str, limit: int = 1, min_relevance_score: float = 0.0, with_embeddings: bool = False, embeddings_kwargs: dict[str, Any] | None = {}) -> list[MemoryQueryResult]
Parameters
| Name | Description |
|---|---|
|
collection
Required
|
The collection to search in. |
|
query
Required
|
The query to search for. |
|
limit
|
The maximum number of results to return. (default: {1}) Default value: 1
|
|
min_relevance_score
|
The minimum relevance score to return. (default: {0.0}) Default value: 0.0
|
|
with_embeddings
|
Whether to return the embeddings of the results. (default: {False}) Default value: False
|
|
embeddings_kwargs
|
The embeddings kwargs of the information. Default value: {}
|
Returns
| Type | Description |
|---|---|
|
The list of MemoryQueryResult found. |
Attributes
is_experimental
is_experimental = True
stage_status
stage_status = 'experimental'