support elasticsearch text only

This commit is contained in:
seehi 2024-03-22 17:30:35 +08:00
parent 34a3c1ad07
commit 092ef26425
4 changed files with 19 additions and 2 deletions

View file

@ -41,7 +41,7 @@ class ConfigBasedFactory(GenericFactory):
if creator:
return creator(key, **kwargs)
raise ValueError(f"Unknown config: {key}")
raise ValueError(f"Unknown config: `{type(key)}`, {key}")
@staticmethod
def _val_from_config_or_kwargs(key: str, config: object = None, **kwargs) -> Any:

View file

@ -14,6 +14,7 @@ from metagpt.rag.schema import (
BM25IndexConfig,
ChromaIndexConfig,
ElasticsearchIndexConfig,
ElasticsearchKeywordIndexConfig,
FAISSIndexConfig,
)
from metagpt.rag.vector_stores.chroma import ChromaVectorStore
@ -26,6 +27,7 @@ class RAGIndexFactory(ConfigBasedFactory):
ChromaIndexConfig: self._create_chroma,
BM25IndexConfig: self._create_bm25,
ElasticsearchIndexConfig: self._create_es,
ElasticsearchKeywordIndexConfig: self._create_es,
}
super().__init__(creators)

View file

@ -20,6 +20,7 @@ from metagpt.rag.schema import (
BaseRetrieverConfig,
BM25RetrieverConfig,
ChromaRetrieverConfig,
ElasticsearchKeywordRetrieverConfig,
ElasticsearchRetrieverConfig,
FAISSRetrieverConfig,
IndexRetrieverConfig,
@ -36,6 +37,7 @@ class RetrieverFactory(ConfigBasedFactory):
BM25RetrieverConfig: self._create_bm25_retriever,
ChromaRetrieverConfig: self._create_chroma_retriever,
ElasticsearchRetrieverConfig: self._create_es_retriever,
ElasticsearchKeywordRetrieverConfig: self._create_es_retriever,
}
super().__init__(creators)

View file

@ -59,12 +59,19 @@ class ElasticsearchStoreConfig(BaseModel):
class ElasticsearchRetrieverConfig(IndexRetrieverConfig):
"""Config for Elasticsearch-based retrievers."""
"""Config for Elasticsearch-based retrievers. Support both vector and text."""
store_config: ElasticsearchStoreConfig = Field(..., description="ElasticsearchStore config.")
vector_store_query_mode: VectorStoreQueryMode = VectorStoreQueryMode.DEFAULT
class ElasticsearchKeywordRetrieverConfig(ElasticsearchRetrieverConfig):
"""Config for Elasticsearch-based retrievers. Support text only."""
_no_embedding: bool = PrivateAttr(default=True)
vector_store_query_mode: VectorStoreQueryMode = VectorStoreQueryMode.TEXT_SEARCH
class BaseRankerConfig(BaseModel):
"""Common config for rankers.
@ -129,6 +136,12 @@ class ElasticsearchIndexConfig(VectorIndexConfig):
persist_path: Union[str, Path] = ""
class ElasticsearchKeywordIndexConfig(ElasticsearchIndexConfig):
"""Config for es-based index. no embedding."""
_no_embedding: bool = PrivateAttr(default=True)
class ObjectNodeMetadata(BaseModel):
"""Metadata of ObjectNode."""