Skip to content

Commit cd43fca

Browse files
author
Zhe Yu
committed
fix(cli): Fix query command by removing deprecated code and chunking queries
1 parent 382297c commit cd43fca

1 file changed

Lines changed: 8 additions & 58 deletions

File tree

src/vectorcode/subcommands/query/__init__.py

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ async def query(configs: Config) -> int:
221221
and QueryInclude.document in configs.include
222222
), "`chunk` and `document` cannot be used at the same time for `--include`."
223223

224+
assert configs.query
225+
chunker = StringChunker(configs)
226+
227+
query_chunks: list[str] = []
228+
for q in configs.query:
229+
query_chunks.extend(str(i) for i in chunker.chunk(q))
230+
configs.query[:] = query_chunks
231+
224232
database = get_database_connector(configs)
225233
reranked_results = await get_reranked_results(configs, database)
226234
formatted_results = _prepare_formatted_result(reranked_results)
@@ -233,61 +241,3 @@ async def query(configs: Config) -> int:
233241
if idx != len(formatted_results) - 1:
234242
print()
235243
return 0
236-
237-
# if (
238-
# QueryInclude.chunk in configs.include
239-
# and QueryInclude.document in configs.include
240-
# ):
241-
# logger.error(
242-
# "Having both chunk and document in the output is not supported!",
243-
# )
244-
# return 1
245-
# async with ClientManager().get_client(configs) as client:
246-
# try:
247-
# collection = await get_collection(client, configs, False)
248-
# if not verify_ef(collection, configs):
249-
# return 1
250-
# except (ValueError, InvalidCollectionException) as e:
251-
# logger.error(
252-
# f"{e.__class__.__name__}: There's no existing collection for {configs.project_root}",
253-
# )
254-
# return 1
255-
# except InvalidDimensionException as e:
256-
# logger.error(
257-
# f"{e.__class__.__name__}: The collection was embedded with a different embedding model.",
258-
# )
259-
# return 1
260-
# except IndexError as e: # pragma: nocover
261-
# logger.error(
262-
# f"{e.__class__.__name__}: Failed to get the collection. Please check your config."
263-
# )
264-
# return 1
265-
#
266-
# if not configs.pipe:
267-
# print("Starting querying...")
268-
#
269-
# if QueryInclude.chunk in configs.include:
270-
# if len((await collection.get(where={"start": {"$gte": 0}}))["ids"]) == 0:
271-
# logger.warning(
272-
# """
273-
# This collection doesn't contain line range metadata. Falling back to `--include path document`.
274-
# Please re-vectorise it to use `--include chunk`.""",
275-
# )
276-
# configs.include = [QueryInclude.path, QueryInclude.document]
277-
#
278-
# try:
279-
# structured_result = await build_query_results(collection, configs)
280-
# except RerankerError as e: # pragma: nocover
281-
# # error logs should be handled where they're raised
282-
# logger.error(f"{e.__class__.__name__}")
283-
# return 1
284-
#
285-
# if configs.pipe:
286-
# print(json.dumps(structured_result))
287-
# else:
288-
# for idx, result in enumerate(structured_result):
289-
# for include_item in configs.include:
290-
# print(f"{include_item.to_header()}{result.get(include_item.value)}")
291-
# if idx != len(structured_result) - 1:
292-
# print()
293-
# return 0

0 commit comments

Comments
 (0)