Skip to content

Commit 538dc4f

Browse files
committed
log upon successful connection to db
1 parent 8289d23 commit 538dc4f

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

vector_db/elastic_provider.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import logging
12
from typing import List
23

34
from langchain_core.documents import Document
45
from langchain_elasticsearch.vectorstores import ElasticsearchStore
56

67
from vector_db.db_provider import DBProvider
78

9+
logger = logging.getLogger(__name__)
10+
811

912
class ElasticProvider(DBProvider):
1013
"""
@@ -28,6 +31,7 @@ class ElasticProvider(DBProvider):
2831

2932
def __init__(self, url: str, password: str, index: str, user: str):
3033
super().__init__()
34+
3135
self.db = ElasticsearchStore(
3236
embedding=self.embeddings,
3337
es_url=url,
@@ -36,6 +40,8 @@ def __init__(self, url: str, password: str, index: str, user: str):
3640
index_name=index,
3741
)
3842

43+
logger.info("Connected to Elasticsearch at %s (index: %s)", url, index)
44+
3945
def add_documents(self, docs: List[Document]) -> None:
4046
"""
4147
Add documents to the Elasticsearch index.

vector_db/pgvector_provider.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import logging
12
from typing import List
3+
from urllib.parse import urlparse
24

35
from langchain_core.documents import Document
46
from langchain_postgres import PGVector
57

68
from vector_db.db_provider import DBProvider
79

10+
logger = logging.getLogger(__name__)
11+
812

913
class PGVectorProvider(DBProvider):
1014
"""
@@ -27,12 +31,23 @@ class PGVectorProvider(DBProvider):
2731

2832
def __init__(self, url: str, collection_name: str):
2933
super().__init__()
34+
3035
self.db = PGVector(
3136
connection=url,
3237
collection_name=collection_name,
3338
embeddings=self.embeddings,
3439
)
3540

41+
parsed = urlparse(url)
42+
postgres_location = (
43+
f"{parsed.hostname}:{parsed.port or 5432}/{parsed.path.lstrip('/')}"
44+
)
45+
logger.info(
46+
"Connected to PGVector at %s (collection: %s)",
47+
postgres_location,
48+
collection_name,
49+
)
50+
3651
def add_documents(self, docs: List[Document]) -> None:
3752
"""
3853
Add a list of documents to the pgvector-backed vector store.

vector_db/qdrant_provider.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from typing import List, Optional
23

34
from langchain_core.documents import Document
@@ -7,6 +8,8 @@
78

89
from vector_db.db_provider import DBProvider
910

11+
logger = logging.getLogger(__name__)
12+
1013

1114
class QdrantProvider(DBProvider):
1215
"""
@@ -31,6 +34,7 @@ class QdrantProvider(DBProvider):
3134
def __init__(self, url: str, collection: str, api_key: Optional[str] = None):
3235
super().__init__()
3336
self.collection = collection
37+
self.url = url
3438

3539
self.client = QdrantClient(
3640
url=url,
@@ -46,11 +50,17 @@ def __init__(self, url: str, collection: str, api_key: Optional[str] = None):
4650
embedding=self.embeddings,
4751
)
4852

53+
logger.info(
54+
"Connected to Qdrant instance at %s (collection: %s)",
55+
self.url,
56+
self.collection,
57+
)
58+
4959
def _collection_exists(self) -> bool:
5060
return self.client.collection_exists(self.collection)
5161

5262
def _create_collection(self) -> None:
53-
vector_size = self.embeddings.embed_query("test").__len__()
63+
vector_size = len(self.embeddings.embed_query("test"))
5464
self.client.recreate_collection(
5565
collection_name=self.collection,
5666
vectors_config=VectorParams(size=vector_size, distance=Distance.COSINE),

vector_db/redis_provider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(self, url: str, index: str, schema: str):
4141
try:
4242
self.redis_client = redis.from_url(self.url)
4343
self.redis_client.ping()
44+
logger.info("Connected to Redis instance at %s", self.url)
4445
except Exception:
4546
logger.exception("Failed to connect to Redis at %s", self.url)
4647
raise

vector_db/sqlserver_provider.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ def __init__(
5959
self.connection_string = self._build_connection_string(self.database)
6060

6161
self._ensure_database_exists()
62+
63+
logger.info(
64+
"Connected to SQL Server at %s:%s, database: %s",
65+
self.host,
66+
self.port,
67+
self.database,
68+
)
69+
6270
self.db = SQLServer_VectorStore(
6371
connection_string=self.connection_string,
6472
embedding_function=self.embeddings,

0 commit comments

Comments
 (0)