tgbot-collection / SearchGram

🔠 Telegram 中文聊天记录搜索机器人 Effortlessly search your Telegram chat history, including CJK languages, with fuzzy and typo-tolerant search capabilities.
GNU General Public License v3.0
251 stars 27 forks source link

感觉 MeiliSearch 非常耗内存,可否尝试 ZincSearch 作为后端 #103

Open antonchen opened 1 year ago

antonchen commented 1 year ago

我有个群需要同步,数据量接近百万,而 MeiliSearch 有文章表明十万数据占用 1.6G 内存。

仅从 README 上看 ZincSearch 似乎更适合做这事,但我没查询到资源占用相关文章

它还有个 Rust 版本支持集群 ZincObserve

BennyThink commented 1 year ago

Thus, if you run Meilisearch as a standalone program on a server, LMDB will use the maximum RAM it can use.

By default, our indexer uses the sysinfo Rust library to calculate a machine's total memory size. Meilisearch then adapts its behavior so indexing uses a maximum two thirds of available resources. Alternatively, you can use the --max-indexing-memory instance option to manually control the maximum amount of RAM Meilisearch can consume.

设置环境变量 MEILI_MAX_INDEXING_MEMORY=800M 来限制内存使用

Sets the maximum amount of RAM Meilisearch can use when indexing. By default, Meilisearch uses no more than two thirds of available memory.

https://www.meilisearch.com/docs/learn/configuration/instance_options#max-indexing-memory

antonchen commented 1 year ago

明白了,我先试试,看看 1G 内存能跑多少数据,同步完再回来反馈。

BennyThink commented 1 year ago

👍 好,坐等反馈

antonchen commented 1 year ago

已同步完成,目前数据量

Pong!
Index telegram has 1022194 documents

Database size: 13.4GiB
Last update: 2023-05-21T02:16:22.23936982Z

当前 MeiliSearch 容器占用 820.6MiB 内存,MEILI_MAX_INDEXING_MEMORY 限制为 2G,同步数据时建议内存限制稍高些。

目前还有问题,add_timestamp.py 已经执行超过 46 小时。由于在 docker 中执行,目前只能看到 231247/1002164 [46:37:15<113:#

BennyThink commented 1 year ago

看起来内存占用还行。时间戳这个只能等了,越到后面越慢,meilisearch的优化问题……

BennyThink commented 1 year ago

https://github.com/meilisearch/product/discussions/652

BennyThink commented 9 months ago

下一个版本准备加上各种不同的适配器,方便任意选择检索引擎

我争取今年做出来🤣

antonchen commented 9 months ago
Pong!
Index telegram has 2373868 documents

Database size: 27.4GiB
Last update: 2023-11-17T08:55:34.792405035Z

目前 MeiliSearch 容器占用 2.443GiB MEILI_MAX_INDEXING_MEMORY 限制为 2GB,因为不常用,运行时间长之后会出现无回复的情况,具体没看日志不知道哪儿的问题。

BennyThink commented 9 months ago

得看个日志才能知道,也可能是 pyrogram 这边的问题

BennyThink commented 8 months ago

已经好了!你试试看!

antonchen commented 8 months ago

已成功运行,几个建议:

  1. zincsearch 的 docker 镜像是以 UID,GID 10001 运行的,环境变量改不了,需要补充文档修改数据目录 chown 10001:10001 ./sg_data/zinc 或打包一份 zincsearch
  2. SearchGram 自身的 zincsearch 相关配置建议和 zincsearch 环境变量统一。这样只用写一份 env_file
  3. 文档中未提及 ENGINE 环境变量说明

MeiliSearch 在我的数据量上会很频繁的占用磁盘的读,机械硬盘经不起它满速读取霍霍。 所以上次提交使用情况后我停用到了现在。

Edit: 数据同步完成后我会再同步资源占用情况。

antonchen commented 8 months ago

@BennyThink 目前没有同步完成,尝试搜索无结果。zincsearch 的 WebUI 搜索同样的关键字没有问题。 日志正常无报错。没有找到调整日志级别的方式提供不了更多日志。

[2024-01-02 09:17:56 connection.py:47 I] Connecting...
[2024-01-02 09:17:56 connection.py:54 I] Connected! Production DC5 - IPv4
[2024-01-02 09:17:56 session.py:294 I] NetworkTask started
[2024-01-02 09:17:56 session.py:139 I] Session initialized: Layer 158
[2024-01-02 09:17:56 session.py:140 I] Device: Firefox - SearchGram/d34f89c
[2024-01-02 09:17:56 session.py:141 I] System: Linux 6.5.0-1-amd64 (en)
[2024-01-02 09:17:56 session.py:155 I] Session started
[2024-01-02 09:17:56 session.py:272 I] PingTask started
BennyThink commented 8 months ago

🤣 搜索修好了

antonchen commented 8 months ago

搜索结果有几个问题:

  1. 搜索香港结果中会出现 ruleset真香,只匹配了一个字的结果
  2. 搜索查询未限制字段,会出现用户名,群名匹配结果
  3. 搜索结果旧的在前,希望可以设置

Edit: zincsearch 需要特定环境变量开启中文分词支持,且索引需要指定分词字段 https://mp.weixin.qq.com/s/g9fcKNSEHqwiK8Tt3MY3GA

BennyThink commented 8 months ago

😓 这个 zinc search 也太难用了.jpg

fengqi commented 1 month ago

你们使用 zinc search 有碰到添加成功但是搜索不到的情况吗(使用自带ui搜索_id或无关键字显示最近1个月的数据) 我测试2000条数据,开启gse_search分词,连续添加到200条左右的时候 zinc 就 oom(2c8g)cpu 100%,然后索引数据条数不再增长,如果尝试硬重启,貌似数据会丢失,就是使用接口添加显示成功,但是索引里永远不会出现这条数据,最终2000条数据只添加进去500左右。

我是其他的场景在使用zinc,而不是SearchGram,我在搜索zinc和meili的时候过来的。

BennyThink commented 1 month ago

用 meili吧

fengqi commented 1 month ago

用 meili吧

感谢反馈,尝试中