Skip to content

Commit 9d185a7

Browse files
author
Zhe Yu
committed
refactor(cli)!: remove common.py
1 parent 5aa1631 commit 9d185a7

8 files changed

Lines changed: 34 additions & 664 deletions

File tree

src/vectorcode/common.py

Lines changed: 0 additions & 320 deletions
This file was deleted.

src/vectorcode/database/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
from vectorcode.chunking import Chunk, TreeSitterChunker
99
from vectorcode.cli_utils import Config
10-
from vectorcode.common import get_embedding_function
1110
from vectorcode.database.types import (
1211
CollectionContent,
1312
CollectionInfo,
1413
QueryResult,
1514
ResultType,
1615
VectoriseStats,
1716
)
17+
from vectorcode.database.utils import get_embedding_function
1818

1919
logger = logging.getLogger(name=__name__)
2020

src/vectorcode/database/utils.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import os
44
import socket
55
import uuid
6+
from functools import cache
67

7-
from vectorcode.cli_utils import expand_path
8+
import chromadb
9+
from chromadb.utils import embedding_functions
10+
11+
from vectorcode.cli_utils import Config, expand_path
812

913
logger = logging.getLogger(name=__name__)
1014

@@ -41,3 +45,27 @@ def get_collection_id(full_path: str) -> str:
4145
f"Hashing {plain_collection_name} as the collection name for {full_path}."
4246
)
4347
return collection_id
48+
49+
50+
@cache
51+
def get_embedding_function(configs: Config) -> chromadb.EmbeddingFunction:
52+
try:
53+
ef = getattr(embedding_functions, configs.embedding_function)(
54+
**configs.embedding_params
55+
)
56+
if ef is None: # pragma: nocover
57+
raise AttributeError()
58+
return ef
59+
except AttributeError:
60+
logger.warning(
61+
f"Failed to use {configs.embedding_function}. Falling back to Sentence Transformer.",
62+
)
63+
return embedding_functions.SentenceTransformerEmbeddingFunction() # type:ignore
64+
except Exception as e:
65+
e.add_note(
66+
"\nFor errors caused by missing dependency, consult the documentation of pipx (or whatever package manager that you installed VectorCode with) for instructions to inject libraries into the virtual environment."
67+
)
68+
logger.error(
69+
f"Failed to use {configs.embedding_function} with following error.",
70+
)
71+
raise

src/vectorcode/lsp_main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
get_project_config,
5050
parse_cli_args,
5151
)
52-
from vectorcode.common import ClientManager
5352
from vectorcode.subcommands.query import (
5453
_prepare_formatted_result,
5554
get_reranked_results,
@@ -322,7 +321,6 @@ async def lsp_start() -> int:
322321
try:
323322
await asyncio.to_thread(server.start_io)
324323
finally:
325-
await ClientManager().kill_servers()
326324
return 0
327325

328326

0 commit comments

Comments
 (0)