mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-06 08:16:00 +00:00
fix: elasticsearch code initialization bug
This commit is contained in:
parent
7f13c3f2fc
commit
69fc75af5f
4 changed files with 31 additions and 5 deletions
|
|
@ -33,10 +33,19 @@ class MemoryscopeContext(object):
|
|||
|
||||
print_workflow_dynamic: bool = False
|
||||
|
||||
log_elasticsearch_dynamic: bool = False
|
||||
|
||||
def get_ms_context():
|
||||
|
||||
def get_memoryscope_uuid():
|
||||
ms_context = MemoryscopeContext()
|
||||
if ms_context.memory_scope_uuid:
|
||||
return ms_context.memory_scope_uuid
|
||||
else:
|
||||
raise RuntimeError("MemoryscopeContext is not initialized yet. Please initialize it first.")
|
||||
|
||||
def get_memoryscope_context():
|
||||
ms_context = MemoryscopeContext()
|
||||
if ms_context.memory_scope_uuid:
|
||||
return ms_context
|
||||
else:
|
||||
raise RuntimeError("MemoryscopeContext is not initialized yet. Please initialize it first.")
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from memoryscope.core.utils.timer import Timer
|
|||
from memoryscope.enumeration.model_enum import ModelEnum
|
||||
from memoryscope.scheme.model_response import ModelResponse, ModelResponseGen
|
||||
from memoryscope.core.memoryscope_context import MemoryscopeContext
|
||||
from memoryscope.core.memoryscope_context import get_ms_context
|
||||
from memoryscope.core.memoryscope_context import get_memoryscope_uuid
|
||||
|
||||
MODEL_REGISTRY = Registry("models")
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ class BaseModel(metaclass=ABCMeta):
|
|||
self.retry_interval: float = retry_interval
|
||||
self.kwargs_filter: bool = kwargs_filter
|
||||
self.raise_exception: bool = raise_exception
|
||||
self.context: MemoryscopeContext = get_ms_context()
|
||||
self.context: MemoryscopeContext = get_memoryscope_uuid()
|
||||
self.kwargs: dict = kwargs
|
||||
|
||||
self._model: Any = None
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ from typing import Any, Callable, Dict, List, Literal, Optional, Union, cast
|
|||
import nest_asyncio
|
||||
import numpy as np
|
||||
from memoryscope.core.utils.logger import Logger
|
||||
from memoryscope.core.memoryscope_context import get_memoryscope_context
|
||||
|
||||
from elasticsearch import AsyncElasticsearch, Elasticsearch
|
||||
from elasticsearch.helpers.vectorstore import (
|
||||
AsyncBM25Strategy,
|
||||
|
|
@ -232,6 +234,17 @@ class ESCombinedRetrieveStrategy(AsyncDenseVectorStrategy):
|
|||
return {"knn": knn}
|
||||
|
||||
|
||||
def before_index_creation(
|
||||
self, *, client: AsyncElasticsearch, text_field: str, vector_field: str
|
||||
) -> None:
|
||||
if self.model_id:
|
||||
from elasticsearch.helpers.vectorstore._async._utils import model_must_be_deployed
|
||||
import asyncio
|
||||
print('before_index_creation')
|
||||
asyncio.run(model_must_be_deployed(client, self.model_id))
|
||||
print('before_index_creation 2')
|
||||
|
||||
|
||||
def _to_elasticsearch_filter(standard_filters: Dict[str, List[str]]) -> Dict[str, Any]:
|
||||
"""
|
||||
Converts standard Llama-index filters into a format compatible with Elasticsearch.
|
||||
|
|
@ -363,6 +376,7 @@ class SyncElasticsearchStore(BasePydanticVectorStore):
|
|||
distance_strategy: Optional[DISTANCE_STRATEGIES] = "COSINE"
|
||||
retrieval_strategy: AsyncRetrievalStrategy
|
||||
logger: Logger = None
|
||||
log_elasticsearch_dynamic: bool = False
|
||||
|
||||
_store = PrivateAttr()
|
||||
|
||||
|
|
@ -429,6 +443,7 @@ class SyncElasticsearchStore(BasePydanticVectorStore):
|
|||
)
|
||||
|
||||
self.logger = Logger.get_logger("elastic_search")
|
||||
self.log_elasticsearch_dynamic = get_memoryscope_context().log_elasticsearch_dynamic
|
||||
|
||||
@property
|
||||
def client(self) -> Any:
|
||||
|
|
@ -625,6 +640,8 @@ class SyncElasticsearchStore(BasePydanticVectorStore):
|
|||
return search_res
|
||||
|
||||
def log_vector_store_brief(self, title="current vector store content"):
|
||||
if not self.log_elasticsearch_dynamic:
|
||||
return "Dynamic elasticsearch logging is disabled to enhance performance."
|
||||
search_res = self.sync_search_all()
|
||||
|
||||
brief = {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ def rich2text(rich_table):
|
|||
return '\n' + str(Text.from_ansi(capture.get()))
|
||||
|
||||
def append_memoryscope_uuid(dir_path):
|
||||
from memoryscope.core.memoryscope_context import get_ms_context # pylint: disable=import-outside-toplevel
|
||||
dir_path = os.path.join(dir_path, get_ms_context())
|
||||
from memoryscope.core.memoryscope_context import get_memoryscope_uuid # pylint: disable=import-outside-toplevel
|
||||
dir_path = os.path.join(dir_path, get_memoryscope_uuid())
|
||||
return dir_path
|
||||
|
||||
class Logger(logging.Logger):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue