-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring vectordb naming convention in embedchain.config (#1469)
- Loading branch information
1 parent
1a5d0d2
commit 83e8c97
Showing
20 changed files
with
124 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
embedchain/config/vectordb/chroma.py → embedchain/config/vector_db/chroma.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 56 additions & 56 deletions
112
embedchain/config/vectordb/elasticsearch.py → embedchain/config/vector_db/elasticsearch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
import os | ||
from typing import Optional, Union | ||
|
||
from embedchain.config.vectordb.base import BaseVectorDbConfig | ||
from embedchain.helpers.json_serializable import register_deserializable | ||
|
||
|
||
@register_deserializable | ||
class ElasticsearchDBConfig(BaseVectorDbConfig): | ||
def __init__( | ||
self, | ||
collection_name: Optional[str] = None, | ||
dir: Optional[str] = None, | ||
es_url: Union[str, list[str]] = None, | ||
cloud_id: Optional[str] = None, | ||
batch_size: Optional[int] = 100, | ||
**ES_EXTRA_PARAMS: dict[str, any], | ||
): | ||
""" | ||
Initializes a configuration class instance for an Elasticsearch client. | ||
:param collection_name: Default name for the collection, defaults to None | ||
:type collection_name: Optional[str], optional | ||
:param dir: Path to the database directory, where the database is stored, defaults to None | ||
:type dir: Optional[str], optional | ||
:param es_url: elasticsearch url or list of nodes url to be used for connection, defaults to None | ||
:type es_url: Union[str, list[str]], optional | ||
:param cloud_id: cloud id of the elasticsearch cluster, defaults to None | ||
:type cloud_id: Optional[str], optional | ||
:param batch_size: Number of items to insert in one batch, defaults to 100 | ||
:type batch_size: Optional[int], optional | ||
:param ES_EXTRA_PARAMS: extra params dict that can be passed to elasticsearch. | ||
:type ES_EXTRA_PARAMS: dict[str, Any], optional | ||
""" | ||
if es_url and cloud_id: | ||
raise ValueError("Only one of `es_url` and `cloud_id` can be set.") | ||
# self, es_url: Union[str, list[str]] = None, **ES_EXTRA_PARAMS: dict[str, any]): | ||
self.ES_URL = es_url or os.environ.get("ELASTICSEARCH_URL") | ||
self.CLOUD_ID = cloud_id or os.environ.get("ELASTICSEARCH_CLOUD_ID") | ||
if not self.ES_URL and not self.CLOUD_ID: | ||
raise AttributeError( | ||
"Elasticsearch needs a URL or CLOUD_ID attribute, " | ||
"this can either be passed to `ElasticsearchDBConfig` or as `ELASTICSEARCH_URL` or `ELASTICSEARCH_CLOUD_ID` in `.env`" # noqa: E501 | ||
) | ||
self.ES_EXTRA_PARAMS = ES_EXTRA_PARAMS | ||
# Load API key from .env if it's not explicitly passed. | ||
# Can only set one of 'api_key', 'basic_auth', and 'bearer_auth' | ||
if ( | ||
not self.ES_EXTRA_PARAMS.get("api_key") | ||
and not self.ES_EXTRA_PARAMS.get("basic_auth") | ||
and not self.ES_EXTRA_PARAMS.get("bearer_auth") | ||
): | ||
self.ES_EXTRA_PARAMS["api_key"] = os.environ.get("ELASTICSEARCH_API_KEY") | ||
|
||
self.batch_size = batch_size | ||
super().__init__(collection_name=collection_name, dir=dir) | ||
import os | ||
from typing import Optional, Union | ||
|
||
from embedchain.config.vector_db.base import BaseVectorDbConfig | ||
from embedchain.helpers.json_serializable import register_deserializable | ||
|
||
|
||
@register_deserializable | ||
class ElasticsearchDBConfig(BaseVectorDbConfig): | ||
def __init__( | ||
self, | ||
collection_name: Optional[str] = None, | ||
dir: Optional[str] = None, | ||
es_url: Union[str, list[str]] = None, | ||
cloud_id: Optional[str] = None, | ||
batch_size: Optional[int] = 100, | ||
**ES_EXTRA_PARAMS: dict[str, any], | ||
): | ||
""" | ||
Initializes a configuration class instance for an Elasticsearch client. | ||
:param collection_name: Default name for the collection, defaults to None | ||
:type collection_name: Optional[str], optional | ||
:param dir: Path to the database directory, where the database is stored, defaults to None | ||
:type dir: Optional[str], optional | ||
:param es_url: elasticsearch url or list of nodes url to be used for connection, defaults to None | ||
:type es_url: Union[str, list[str]], optional | ||
:param cloud_id: cloud id of the elasticsearch cluster, defaults to None | ||
:type cloud_id: Optional[str], optional | ||
:param batch_size: Number of items to insert in one batch, defaults to 100 | ||
:type batch_size: Optional[int], optional | ||
:param ES_EXTRA_PARAMS: extra params dict that can be passed to elasticsearch. | ||
:type ES_EXTRA_PARAMS: dict[str, Any], optional | ||
""" | ||
if es_url and cloud_id: | ||
raise ValueError("Only one of `es_url` and `cloud_id` can be set.") | ||
# self, es_url: Union[str, list[str]] = None, **ES_EXTRA_PARAMS: dict[str, any]): | ||
self.ES_URL = es_url or os.environ.get("ELASTICSEARCH_URL") | ||
self.CLOUD_ID = cloud_id or os.environ.get("ELASTICSEARCH_CLOUD_ID") | ||
if not self.ES_URL and not self.CLOUD_ID: | ||
raise AttributeError( | ||
"Elasticsearch needs a URL or CLOUD_ID attribute, " | ||
"this can either be passed to `ElasticsearchDBConfig` or as `ELASTICSEARCH_URL` or `ELASTICSEARCH_CLOUD_ID` in `.env`" # noqa: E501 | ||
) | ||
self.ES_EXTRA_PARAMS = ES_EXTRA_PARAMS | ||
# Load API key from .env if it's not explicitly passed. | ||
# Can only set one of 'api_key', 'basic_auth', and 'bearer_auth' | ||
if ( | ||
not self.ES_EXTRA_PARAMS.get("api_key") | ||
and not self.ES_EXTRA_PARAMS.get("basic_auth") | ||
and not self.ES_EXTRA_PARAMS.get("bearer_auth") | ||
): | ||
self.ES_EXTRA_PARAMS["api_key"] = os.environ.get("ELASTICSEARCH_API_KEY") | ||
|
||
self.batch_size = batch_size | ||
super().__init__(collection_name=collection_name, dir=dir) |
2 changes: 1 addition & 1 deletion
2
embedchain/config/vectordb/lancedb.py → embedchain/config/vector_db/lancedb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 41 additions & 41 deletions
82
embedchain/config/vectordb/opensearch.py → embedchain/config/vector_db/opensearch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
from typing import Optional | ||
|
||
from embedchain.config.vectordb.base import BaseVectorDbConfig | ||
from embedchain.helpers.json_serializable import register_deserializable | ||
|
||
|
||
@register_deserializable | ||
class OpenSearchDBConfig(BaseVectorDbConfig): | ||
def __init__( | ||
self, | ||
opensearch_url: str, | ||
http_auth: tuple[str, str], | ||
vector_dimension: int = 1536, | ||
collection_name: Optional[str] = None, | ||
dir: Optional[str] = None, | ||
batch_size: Optional[int] = 100, | ||
**extra_params: dict[str, any], | ||
): | ||
""" | ||
Initializes a configuration class instance for an OpenSearch client. | ||
:param collection_name: Default name for the collection, defaults to None | ||
:type collection_name: Optional[str], optional | ||
:param opensearch_url: URL of the OpenSearch domain | ||
:type opensearch_url: str, Eg, "http://localhost:9200" | ||
:param http_auth: Tuple of username and password | ||
:type http_auth: tuple[str, str], Eg, ("username", "password") | ||
:param vector_dimension: Dimension of the vector, defaults to 1536 (openai embedding model) | ||
:type vector_dimension: int, optional | ||
:param dir: Path to the database directory, where the database is stored, defaults to None | ||
:type dir: Optional[str], optional | ||
:param batch_size: Number of items to insert in one batch, defaults to 100 | ||
:type batch_size: Optional[int], optional | ||
""" | ||
self.opensearch_url = opensearch_url | ||
self.http_auth = http_auth | ||
self.vector_dimension = vector_dimension | ||
self.extra_params = extra_params | ||
self.batch_size = batch_size | ||
|
||
super().__init__(collection_name=collection_name, dir=dir) | ||
from typing import Optional | ||
|
||
from embedchain.config.vector_db.base import BaseVectorDbConfig | ||
from embedchain.helpers.json_serializable import register_deserializable | ||
|
||
|
||
@register_deserializable | ||
class OpenSearchDBConfig(BaseVectorDbConfig): | ||
def __init__( | ||
self, | ||
opensearch_url: str, | ||
http_auth: tuple[str, str], | ||
vector_dimension: int = 1536, | ||
collection_name: Optional[str] = None, | ||
dir: Optional[str] = None, | ||
batch_size: Optional[int] = 100, | ||
**extra_params: dict[str, any], | ||
): | ||
""" | ||
Initializes a configuration class instance for an OpenSearch client. | ||
:param collection_name: Default name for the collection, defaults to None | ||
:type collection_name: Optional[str], optional | ||
:param opensearch_url: URL of the OpenSearch domain | ||
:type opensearch_url: str, Eg, "http://localhost:9200" | ||
:param http_auth: Tuple of username and password | ||
:type http_auth: tuple[str, str], Eg, ("username", "password") | ||
:param vector_dimension: Dimension of the vector, defaults to 1536 (openai embedding model) | ||
:type vector_dimension: int, optional | ||
:param dir: Path to the database directory, where the database is stored, defaults to None | ||
:type dir: Optional[str], optional | ||
:param batch_size: Number of items to insert in one batch, defaults to 100 | ||
:type batch_size: Optional[int], optional | ||
""" | ||
self.opensearch_url = opensearch_url | ||
self.http_auth = http_auth | ||
self.vector_dimension = vector_dimension | ||
self.extra_params = extra_params | ||
self.batch_size = batch_size | ||
|
||
super().__init__(collection_name=collection_name, dir=dir) |
2 changes: 1 addition & 1 deletion
2
embedchain/config/vectordb/pinecone.py → embedchain/config/vector_db/pinecone.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
embedchain/config/vectordb/qdrant.py → embedchain/config/vector_db/qdrant.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
embedchain/config/vectordb/weaviate.py → embedchain/config/vector_db/weaviate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
embedchain/config/vectordb/zilliz.py → embedchain/config/vector_db/zilliz.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters