Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Add schema validation and placeholders to index mappings #3240

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
18eedf6
feat(index mappings): fetch mappings and version from json file inste…
pyek-bot Oct 23, 2024
7068729
refactor: changing exception being thrown
pyek-bot Oct 23, 2024
abd4b25
chore: remove unused file
pyek-bot Oct 23, 2024
d2f3c0e
chore: fix typo in comment
pyek-bot Oct 23, 2024
fa81560
chore: adding new line at the end of files
pyek-bot Oct 23, 2024
63a6d62
feat: add test cases
pyek-bot Oct 24, 2024
8cbaf01
fix: remove test code
pyek-bot Oct 24, 2024
3423026
fix(test): in main the versions were not updated appropriately
pyek-bot Oct 24, 2024
67a1810
refactor: move mapping templates under common module
pyek-bot Oct 25, 2024
63bc70d
refactor: ensure that conversationindexconstants reference mlindex en…
pyek-bot Oct 29, 2024
88673ed
refactor: update comment
pyek-bot Oct 29, 2024
409fbd9
feat: add enhancements to validate index schema and allow using place…
pyek-bot Oct 30, 2024
9776787
Merge branch 'fetch_index_mappings_from_files' into enhancements_fetc…
pyek-bot Oct 30, 2024
af4d1d0
refactor: modifying comment
pyek-bot Oct 30, 2024
b383b48
test: adding testcase for MLIndex to catch failures before runtime
pyek-bot Oct 30, 2024
56d945b
refactor: rename dir from mappings to index-mappings
pyek-bot Oct 31, 2024
4ea99ea
fix: add null checks
pyek-bot Oct 31, 2024
6bef762
fix conflicts and merge parent
pyek-bot Oct 31, 2024
ba9d232
fix: modify mappin paths for placeholders
pyek-bot Oct 31, 2024
ce72e53
fix: adding dependencies for testing
pyek-bot Nov 2, 2024
e714c35
fix(test): compare json object rather than strings to avoid eol chara…
pyek-bot Nov 5, 2024
d50a9f9
Merge branch 'main' into fetch_index_mappings_from_files
pyek-bot Nov 25, 2024
86d2b76
refactor: combine if statements into single check
pyek-bot Nov 26, 2024
1cd16b2
refactoring: null handling + clean code
pyek-bot Nov 26, 2024
369475d
spotless apply
pyek-bot Nov 26, 2024
313b70d
merge parent and fix conflicts
pyek-bot Nov 26, 2024
d8390ca
tests: adding more UT
pyek-bot Nov 26, 2024
cba2c88
fix: dependencies to handle jarhell
pyek-bot Nov 26, 2024
d7b19ea
merge main and fix conflicts
pyek-bot Nov 27, 2024
2884b50
spotless apply
pyek-bot Nov 27, 2024
3e45f6e
refactor: add header and use single instance of mapper
pyek-bot Dec 4, 2024
399b892
fixed: doc syntax
pyek-bot Dec 13, 2024
59998c2
refactor: renamed files, efficient loading of resources, better excep…
pyek-bot Dec 27, 2024
4747861
refactor: cleaner comment
pyek-bot Dec 27, 2024
867e97d
Merge branch 'main' into enhancements_fetch_index_mappings_from_files
pyek-bot Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.engine.indices;
package org.opensearch.ml.common;

import static org.opensearch.ml.common.CommonValue.ML_AGENT_INDEX;
import static org.opensearch.ml.common.CommonValue.ML_AGENT_INDEX_MAPPING_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
package org.opensearch.ml.common.conversation;

import org.opensearch.common.settings.Setting;
import org.opensearch.ml.common.MLIndex;

/**
* Class containing a bunch of constant defining how the conversational indices are formatted
* ToDo: use MLIndex.MEMORY_MESSAGE and MLIndex.MEMORY_META directly for index names and mappings rather than constants
*/
public class ConversationalIndexConstants {
/** Version of the meta index schema */
public final static Integer META_INDEX_SCHEMA_VERSION = 2;
/** Name of the conversational metadata index */
public final static String META_INDEX_NAME = ".plugins-ml-memory-meta";
public final static String META_INDEX_NAME = MLIndex.MEMORY_META.getIndexName();
/** Name of the metadata field for initial timestamp */
public final static String META_CREATED_TIME_FIELD = "create_time";
/** Name of the metadata field for updated timestamp */
Expand All @@ -41,38 +41,10 @@ public class ConversationalIndexConstants {
public final static String META_ADDITIONAL_INFO_FIELD = "additional_info";

/** Mappings for the conversational metadata index */
public final static String META_MAPPING = "{\n"
+ " \"_meta\": {\n"
+ " \"schema_version\": "
+ META_INDEX_SCHEMA_VERSION
+ "\n"
+ " },\n"
+ " \"properties\": {\n"
+ " \""
+ META_NAME_FIELD
+ "\": {\"type\": \"text\"},\n"
+ " \""
+ META_CREATED_TIME_FIELD
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n"
+ " \""
+ META_UPDATED_TIME_FIELD
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n"
+ " \""
+ USER_FIELD
+ "\": {\"type\": \"keyword\"},\n"
+ " \""
+ APPLICATION_TYPE_FIELD
+ "\": {\"type\": \"keyword\"},\n"
+ " \""
+ META_ADDITIONAL_INFO_FIELD
+ "\": {\"type\": \"flat_object\"}\n"
+ " }\n"
+ "}";
public final static String META_MAPPING = MLIndex.MEMORY_META.getMapping();

/** Version of the interactions index schema */
public final static Integer INTERACTIONS_INDEX_SCHEMA_VERSION = 1;
/** Name of the conversational interactions index */
public final static String INTERACTIONS_INDEX_NAME = ".plugins-ml-memory-message";
public final static String INTERACTIONS_INDEX_NAME = MLIndex.MEMORY_MESSAGE.getIndexName();
/** Name of the interaction field for the conversation Id */
public final static String INTERACTIONS_CONVERSATION_ID_FIELD = "memory_id";
/** Name of the interaction field for the human input */
Expand All @@ -92,42 +64,7 @@ public class ConversationalIndexConstants {
/** The trace number of an interaction */
public final static String INTERACTIONS_TRACE_NUMBER_FIELD = "trace_number";
/** Mappings for the interactions index */
public final static String INTERACTIONS_MAPPINGS = "{\n"
+ " \"_meta\": {\n"
+ " \"schema_version\": "
+ INTERACTIONS_INDEX_SCHEMA_VERSION
+ "\n"
+ " },\n"
+ " \"properties\": {\n"
+ " \""
+ INTERACTIONS_CONVERSATION_ID_FIELD
+ "\": {\"type\": \"keyword\"},\n"
+ " \""
+ INTERACTIONS_CREATE_TIME_FIELD
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n"
+ " \""
+ INTERACTIONS_INPUT_FIELD
+ "\": {\"type\": \"text\"},\n"
+ " \""
+ INTERACTIONS_PROMPT_TEMPLATE_FIELD
+ "\": {\"type\": \"text\"},\n"
+ " \""
+ INTERACTIONS_RESPONSE_FIELD
+ "\": {\"type\": \"text\"},\n"
+ " \""
+ INTERACTIONS_ORIGIN_FIELD
+ "\": {\"type\": \"keyword\"},\n"
+ " \""
+ INTERACTIONS_ADDITIONAL_INFO_FIELD
+ "\": {\"type\": \"flat_object\"},\n"
+ " \""
+ PARENT_INTERACTIONS_ID_FIELD
+ "\": {\"type\": \"keyword\"},\n"
+ " \""
+ INTERACTIONS_TRACE_NUMBER_FIELD
+ "\": {\"type\": \"long\"}\n"
+ " }\n"
+ "}";
public final static String INTERACTIONS_MAPPINGS = MLIndex.MEMORY_MESSAGE.getMapping();

/** Feature Flag setting for conversational memory */
public static final Setting<Boolean> ML_COMMONS_MEMORY_FEATURE_ENABLED = Setting
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/resources/mappings/ml-memory-meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
},
"application_type": {
"type": "keyword"
},
"additional_info": {
"type": "flat_object"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.opensearch.ml.common.AccessMode;
import org.opensearch.ml.common.CommonValue;
import org.opensearch.ml.common.FunctionName;
import org.opensearch.ml.common.MLIndex;
import org.opensearch.ml.common.MLModel;
import org.opensearch.ml.common.MLModelGroup;
import org.opensearch.ml.common.MLTask;
Expand Down Expand Up @@ -68,7 +69,6 @@
import org.opensearch.ml.common.transport.task.MLTaskGetResponse;
import org.opensearch.ml.engine.algorithms.DLModelExecute;
import org.opensearch.ml.engine.annotation.Function;
import org.opensearch.ml.engine.indices.MLIndex;
import org.opensearch.search.builder.SearchSourceBuilder;

import com.google.common.annotations.VisibleForTesting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.action.ActionListener;
import org.opensearch.ml.common.CommonValue;
import org.opensearch.ml.common.MLIndex;
import org.opensearch.ml.common.exception.MLException;

import lombok.AccessLevel;
Expand Down