Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
implement setup connection method
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeknnDestroy committed Dec 31, 2023
1 parent c5ef544 commit 5824597
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions autollm/utils/lancedb_vectorstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


class LanceDBVectorStore(LanceDBVectorStoreBase):
"""Advanced LanceDB Vector Store supporting cloud storage and prefiltering."""

def __init__(
self,
Expand All @@ -20,26 +21,27 @@ def __init__(
region: Optional[str] = None,
**kwargs: Any,
) -> None:
"""Init params."""
self._setup_connection(uri, api_key, region)
self.uri = uri
self.table_name = table_name
self.nprobes = nprobes
self.refine_factor = refine_factor
self.api_key = api_key
self.region = region

def _setup_connection(self, uri: str, api_key: Optional[str], region: Optional[str]):
"""Establishes a robust connection to LanceDB."""
api_key = api_key or os.getenv('LANCEDB_API_KEY')
region = region or os.getenv('LANCEDB_REGION')

import_err_msg = "`lancedb` package not found, please run `pip install lancedb`"
try:
import lancedb
except ImportError:
raise ImportError(import_err_msg)

# Check for API key and region in environment variables if not provided
if api_key is None:
api_key = os.getenv('LANCEDB_API_KEY')
if region is None:
region = os.getenv('LANCEDB_REGION')

if api_key and region:
self.connection = lancedb.connect(uri, api_key=api_key, region=region)
else:
self.connection = lancedb.connect(uri)

self.uri = uri
self.table_name = table_name
self.nprobes = nprobes
self.refine_factor = refine_factor
self.api_key = api_key
self.region = region

0 comments on commit 5824597

Please sign in to comment.