Orchard Core AI Memory Elasticsearch
Configure Elasticsearch memory indexing
You are an Orchard Core expert. Configure Elasticsearch as the persistent AI Memory
vector backend while maintaining user isolation, stable provider mappings, and
embedding compatibility.
Guidelines
- Enable the exact feature ID
CrestApps.OrchardCore.AI.Memory.Elasticsearch. - Its manifest depends on
CrestApps.OrchardCore.AI.MemoryandOrchardCore.Elasticsearch; the base memory feature is enabled by dependency. - Create AI Memory (Elasticsearch) from Search → Indexing, select an embedding deployment, and choose it in Settings → Artificial Intelligence → Memory.
- The provider is registered as keyed
IMemoryVectorSearchServiceusingElasticsearchConstants.ProviderName. - Vector similarity never replaces authorization. Every retrieval must remain filtered to the current authenticated
userId. - Install this package in the web or startup project and secure the Elasticsearch connection with production secret configuration.
- Store only durable non-sensitive preferences and facts; do not persist credentials, tokens, financial data, or private keys as AI memory.
Provider registrations
| Registration | Purpose |
|---|---|
| AIMemoryElasticsearchIndexProfileHandler | Defines memory mappings, vector dimensions, and default search fields. |
| AIMemoryElasticsearchDocumentIndexHandler | Maps persisted memory records to Elasticsearch documents. |
| ElasticsearchMemoryVectorSearchService | Runs user-filtered k-nearest-neighbor queries. |
| AddElasticsearchIndexingSource | Adds AI Memory (Elasticsearch) at Search → Indexing. |
Enable the backend
{
"steps": [
{
"name": "Feature",
"enable": [
"CrestApps.OrchardCore.AI",
"CrestApps.OrchardCore.AI.Memory.Elasticsearch",
"OrchardCore.Elasticsearch"
],
"disable": []
}
]
}
The core AI Memory feature comes from the provider dependency. Use the Azure AI Search
provider instead when that is the selected index service; do not configure both as
masters unless the application intentionally manages separate indexes and migration.
Configure the profile
- Configure Orchard Core Elasticsearch connectivity and permissions.
- Create an embedding deployment that declares
textEmbedding; the picker lists deployments in theembeddingslot only (seeorchardcore-ai-model-capabilities). - Create AI Memory (Elasticsearch) under Search → Indexing.
- Select the embedding deployment and save. It is stored in
DataSourceIndexProfileMetadata.EmbeddingDeploymentNameand becomes read-only once the index exists. - Select the profile in the AI Memory site setting.
- Enable user memory for the desired AI profile or interaction, then test as an authenticated user.
The profile's embedding deployment defines dense-vector dimensions. If dimensions
change, create a new compatible index and reindex instead of mixing incompatible vectors.
Managed mappings
| Field | Elasticsearch mapping |
|---|---|
| memoryId | Keyword and index key |
| userId | Keyword |
| name | Text |
| description | Text |
| content | Text |
| updatedUtc | Date |
| embedding | Indexed dense_vector using cosine similarity |
The handler uses selected embedding dimensions for embedding. When the profile has
no default Elasticsearch query fields, it assigns name, description, and content.
Do not change the key field away from memoryId; indexing updates and deletions depend
on the stable identifier.
Vector retrieval behavior
ElasticsearchMemoryVectorSearchService searches the profile IndexFullName with:
embeddingas the k-nearest-neighbor fieldK = topNNumCandidates = topN * 10- a
userIdterm filter for the current authenticated user
It maps memory ID, name, description, content, updated time, and score from each hit.
Results without content are discarded, then remaining results are ordered by score and
limited to topN. Invalid responses and exceptions are logged and produce an empty
result set.
Retrieval sequence
- The current authenticated user submits a memory-aware request.
- The query is embedded with the memory profile deployment.
- The Elasticsearch keyed memory service executes filtered k-nearest-neighbor search.
- Relevant user-specific records become private retrieval context or tool results.
- The application never exposes hits from another user's
userId.
Troubleshooting
| Symptom | Check |
|---|---|
| AI Memory index source is absent | Enable OrchardCore.Elasticsearch and the exact provider feature. |
| Index rejects a mapping | Verify Elasticsearch version support and the selected embedding vector dimensions. |
| No memories are returned | Verify an authenticated identity, selected master profile, saved records, and index health. |
| Search error is logged | Inspect Elasticsearch endpoint, TLS, credentials, index availability, and network access. |
| Results cross user boundaries | Stop and correct the query. Preserve the mandatory userId term filter. |
| Textual memory queries behave unexpectedly | Review default query metadata; the handler assigns Name, Description, and Content only when no defaults exist. |
Security and operations
- Use TLS, least-privilege credentials, and restricted network access for Elasticsearch.
- Validate user isolation with two distinct accounts before production rollout.
- Reindex after an intentional embedding deployment or vector-dimension change.
- Keep users informed about memory retention and support their removal requests.
- Do not bypass the shared memory store lifecycle with direct index writes unless the application also preserves indexing consistency.
Profile maintenance
The provider handler initializes, creates, and updates Elasticsearch index profiles.
It sets mapping metadata only for profiles it can handle:
- Confirm the profile provider is Elasticsearch.
- Confirm the selected embedding deployment is still available and dimension-compatible.
- Save the profile through Search → Indexing so managed properties remain valid.
- Preserve
memoryIdas the key and theuserIdkeyword mapping for filtering. - Reindex through the shared memory lifecycle after mapping or embedding changes.
Add custom fields only with new names. Do not replace the dense_vector field,
change its cosine similarity setting, or remove userId from an index that backs
shared authenticated-user memory.
Index migration checklist
- Create a new index profile for an embedding deployment with changed dimensions.
- Create and validate the target Elasticsearch index before selecting it as master.
- Reindex memory records using the normal indexing service rather than direct bulk writes.
- Test semantic search, save, update, removal, and self-service memory clearing.
- Monitor index health and failed indexing work before diagnosing semantic retrieval.