Skip to content

Commit 7993c3a

Browse files
zhixiangxuefridayL
andauthored
fix: update deprecated APIs for chonkie v1.4.0 and qdrant-client v1.16.0 (#705)
* fix: update deprecated APIs and dependency versions * feat: add chonkie API version compatibility * chore: update poetry.lock for chonkie version compatibility --------- Co-authored-by: chunyu li <[email protected]>
1 parent c0b7228 commit 7993c3a

File tree

5 files changed

+53
-38
lines changed

5 files changed

+53
-38
lines changed

poetry.lock

Lines changed: 28 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ all = [
119119
# We kindof don't want users to install them.
120120
"torch (>=2.7.1,<3.0.0)",
121121
"sentence-transformers (>=4.1.0,<5.0.0)",
122-
"qdrant-client (>=1.14.2,<2.0.0)",
122+
"qdrant-client (>=1.16.0,<2.0.0)",
123123
"volcengine-python-sdk (>=4.0.4,<5.0.0)",
124124
"nltk (>=3.9.1,<4.0.0)",
125125
"rake-nltk (>=1.0.6,<1.1.0)",

src/memos/chunkers/sentence_chunker.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,25 @@ def __init__(self, config: SentenceChunkerConfig):
2020
from chonkie import SentenceChunker as ChonkieSentenceChunker
2121

2222
self.config = config
23-
self.chunker = ChonkieSentenceChunker(
24-
tokenizer_or_token_counter=config.tokenizer_or_token_counter,
25-
chunk_size=config.chunk_size,
26-
chunk_overlap=config.chunk_overlap,
27-
min_sentences_per_chunk=config.min_sentences_per_chunk,
28-
)
23+
24+
# Try new API first (v1.4.0+)
25+
try:
26+
self.chunker = ChonkieSentenceChunker(
27+
tokenizer=config.tokenizer_or_token_counter,
28+
chunk_size=config.chunk_size,
29+
chunk_overlap=config.chunk_overlap,
30+
min_sentences_per_chunk=config.min_sentences_per_chunk,
31+
)
32+
except (TypeError, AttributeError) as e:
33+
# Fallback to old API (<v1.4.0)
34+
logger.debug(f"Falling back to old chonkie API: {e}")
35+
self.chunker = ChonkieSentenceChunker(
36+
tokenizer_or_token_counter=config.tokenizer_or_token_counter,
37+
chunk_size=config.chunk_size,
38+
chunk_overlap=config.chunk_overlap,
39+
min_sentences_per_chunk=config.min_sentences_per_chunk,
40+
)
41+
2942
logger.info(f"Initialized SentenceChunker with config: {config}")
3043

3144
def chunk(self, text: str) -> list[str] | list[Chunk]:

src/memos/mem_os/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import time
44

5-
from datetime import datetime
5+
from datetime import datetime, timezone
66
from pathlib import Path
77
from threading import Lock
88
from typing import Any, Literal
@@ -192,7 +192,7 @@ def _register_chat_history(
192192
self.chat_history_manager[user_id] = ChatHistory(
193193
user_id=user_id if user_id is not None else self.user_id,
194194
session_id=session_id if session_id is not None else self.session_id,
195-
created_at=datetime.utcnow(),
195+
created_at=datetime.now(timezone.utc),
196196
total_messages=0,
197197
chat_history=[],
198198
)

src/memos/vec_dbs/qdrant.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ def search(
138138
List of search results with distance scores and payloads.
139139
"""
140140
qdrant_filter = self._dict_to_filter(filter) if filter else None
141-
response = self.client.search(
141+
response = self.client.query_points(
142142
collection_name=self.config.collection_name,
143-
query_vector=query_vector,
143+
query=query_vector,
144144
limit=top_k,
145145
query_filter=qdrant_filter,
146146
with_vectors=True,
147147
with_payload=True,
148-
)
148+
).points
149149
logger.info(f"Qdrant search completed with {len(response)} results.")
150150
return [
151151
VecDBItem(

0 commit comments

Comments
 (0)