mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-24 18:07:35 +08:00
fix: support dense_vector from ES fields response (ES 9.x compatibility) - [x] Bug Fix (non-breaking change which fixes an issue) - [x] Configuration Chore (non-breaking change which updates configuration) ## Summary by CodeRabbit * **Bug Fixes** * More accurate handling and unwrapping of dense-vector fields so returned values have correct shapes. * Field selection reliably limits returned data and falls back to alternate result locations when needed. * Use of consistent result IDs and tolerant handling when score values are missing. * **Chores / Configuration** * Increased build memory and adjusted build-time flags for the frontend build. * Simplified runtime model/GPU checks and removed an automated runtime GPU-install attempt. * **Build Fixes** * `web/vite.config.ts`: make `build.minify` and `build.sourcemap` respect `VITE_MINIFY` and `VITE_BUILD_SOURCEMAP` env vars from Dockerfile instead of hardcoding `terser` and `true`. * **Environment** * Allow stack version override and default the runtime image tag to "latest". <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Correct unwrapping of dense-vector fields and reliable field selection with fallback locations. * Consistent use of hit-level IDs and tolerant handling when score values are missing. * **Chores / Configuration** * Increased frontend build memory and added build-time minify/sourcemap flags; build minification and sourcemap now configurable. * Removed runtime GPU detection for model initialization; force CPU initialization. * **Environment** * Allow stack version override and default runtime image tag to "latest". <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
168 lines
7.6 KiB
Python
168 lines
7.6 KiB
Python
#
|
|
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
import time
|
|
import uuid
|
|
|
|
import pytest
|
|
import random
|
|
from test_common import create_memory, list_memory, add_message, delete_memory
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
def add_empty_raw_type_memory(request, WebApiAuth):
|
|
def cleanup():
|
|
memory_list_res = list_memory(WebApiAuth)
|
|
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
|
|
for _memory_id in exist_memory_ids:
|
|
delete_memory(WebApiAuth, _memory_id)
|
|
request.addfinalizer(cleanup)
|
|
payload = {
|
|
"name": "test_memory_0",
|
|
"memory_type": ["raw"],
|
|
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
|
|
"llm_id": "glm-4-flash@ZHIPU-AI"
|
|
}
|
|
res = create_memory(WebApiAuth, payload)
|
|
memory_id = res["data"]["id"]
|
|
request.cls.memory_id = memory_id
|
|
request.cls.memory_type = payload["memory_type"]
|
|
return memory_id
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
def add_empty_multiple_type_memory(request, WebApiAuth):
|
|
def cleanup():
|
|
memory_list_res = list_memory(WebApiAuth)
|
|
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
|
|
for _memory_id in exist_memory_ids:
|
|
delete_memory(WebApiAuth, _memory_id)
|
|
request.addfinalizer(cleanup)
|
|
payload = {
|
|
"name": "test_memory_0",
|
|
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(1, 3)),
|
|
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
|
|
"llm_id": "glm-4-flash@ZHIPU-AI"
|
|
}
|
|
res = create_memory(WebApiAuth, payload)
|
|
memory_id = res["data"]["id"]
|
|
request.cls.memory_id = memory_id
|
|
request.cls.memory_type = payload["memory_type"]
|
|
return memory_id
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
def add_2_multiple_type_memory(request, WebApiAuth):
|
|
def cleanup():
|
|
memory_list_res = list_memory(WebApiAuth)
|
|
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
|
|
for _memory_id in exist_memory_ids:
|
|
delete_memory(WebApiAuth, _memory_id)
|
|
|
|
request.addfinalizer(cleanup)
|
|
memory_ids = []
|
|
for i in range(2):
|
|
payload = {
|
|
"name": f"test_memory_{i}",
|
|
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(1, 3)),
|
|
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
|
|
"llm_id": "glm-4-flash@ZHIPU-AI"
|
|
}
|
|
res = create_memory(WebApiAuth, payload)
|
|
memory_ids.append(res["data"]["id"])
|
|
request.cls.memory_ids = memory_ids
|
|
return memory_ids
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
def add_memory_with_multiple_type_message_func(request, WebApiAuth):
|
|
def cleanup():
|
|
memory_list_res = list_memory(WebApiAuth)
|
|
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
|
|
for _memory_id in exist_memory_ids:
|
|
delete_memory(WebApiAuth, _memory_id)
|
|
|
|
request.addfinalizer(cleanup)
|
|
|
|
payload = {
|
|
"name": "test_memory_0",
|
|
"memory_type": ["raw"] + random.choices(["semantic", "episodic", "procedural"], k=random.randint(1, 3)),
|
|
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
|
|
"llm_id": "glm-4-flash@ZHIPU-AI"
|
|
}
|
|
res = create_memory(WebApiAuth, payload)
|
|
memory_id = res["data"]["id"]
|
|
agent_id = uuid.uuid4().hex
|
|
message_payload = {
|
|
"memory_id": [memory_id],
|
|
"agent_id": agent_id,
|
|
"session_id": uuid.uuid4().hex,
|
|
"user_id": "",
|
|
"user_input": "what is coriander?",
|
|
"agent_response": """
|
|
Coriander is a versatile herb with two main edible parts, and its name can refer to both:
|
|
1. Leaves and Stems (often called Cilantro or Fresh Coriander): These are the fresh, green, fragrant leaves and tender stems of the plant Coriandrum sativum. They have a bright, citrusy, and sometimes pungent flavor. Cilantro is widely used as a garnish or key ingredient in cuisines like Mexican, Indian, Thai, and Middle Eastern.
|
|
2. Seeds (called Coriander Seeds): These are the dried, golden-brown seeds of the same plant. When ground, they become coriander powder. The seeds have a warm, nutty, floral, and slightly citrusy taste, completely different from the fresh leaves. They are a fundamental spice in curries, stews, pickles, and baking.
|
|
Key Point of Confusion: The naming differs by region. In North America, "coriander" typically refers to the seeds, while "cilantro" refers to the fresh leaves. In the UK, Europe, and many other parts of the world, "coriander" refers to the fresh herb, and the seeds are called "coriander seeds."
|
|
"""
|
|
}
|
|
add_message(WebApiAuth, message_payload)
|
|
request.cls.memory_id = memory_id
|
|
request.cls.agent_id = agent_id
|
|
time.sleep(2) # make sure refresh to index before search
|
|
return memory_id
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
def add_memory_with_5_raw_message_func(request, WebApiAuth):
|
|
def cleanup():
|
|
memory_list_res = list_memory(WebApiAuth)
|
|
exist_memory_ids = [memory["id"] for memory in memory_list_res["data"]["memory_list"]]
|
|
for _memory_id in exist_memory_ids:
|
|
delete_memory(WebApiAuth, _memory_id)
|
|
|
|
request.addfinalizer(cleanup)
|
|
|
|
payload = {
|
|
"name": "test_memory_1",
|
|
"memory_type": ["raw"],
|
|
"embd_id": "BAAI/bge-small-en-v1.5@Builtin",
|
|
"llm_id": "glm-4-flash@ZHIPU-AI"
|
|
}
|
|
res = create_memory(WebApiAuth, payload)
|
|
memory_id = res["data"]["id"]
|
|
agent_ids = [uuid.uuid4().hex for _ in range(2)]
|
|
session_ids = [uuid.uuid4().hex for _ in range(5)]
|
|
for i in range(5):
|
|
message_payload = {
|
|
"memory_id": [memory_id],
|
|
"agent_id": agent_ids[i % 2],
|
|
"session_id": session_ids[i],
|
|
"user_id": "",
|
|
"user_input": "what is coriander?",
|
|
"agent_response": """
|
|
Coriander is a versatile herb with two main edible parts, and its name can refer to both:
|
|
1. Leaves and Stems (often called Cilantro or Fresh Coriander): These are the fresh, green, fragrant leaves and tender stems of the plant Coriandrum sativum. They have a bright, citrusy, and sometimes pungent flavor. Cilantro is widely used as a garnish or key ingredient in cuisines like Mexican, Indian, Thai, and Middle Eastern.
|
|
2. Seeds (called Coriander Seeds): These are the dried, golden-brown seeds of the same plant. When ground, they become coriander powder. The seeds have a warm, nutty, floral, and slightly citrusy taste, completely different from the fresh leaves. They are a fundamental spice in curries, stews, pickles, and baking.
|
|
Key Point of Confusion: The naming differs by region. In North America, "coriander" typically refers to the seeds, while "cilantro" refers to the fresh leaves. In the UK, Europe, and many other parts of the world, "coriander" refers to the fresh herb, and the seeds are called "coriander seeds."
|
|
"""
|
|
}
|
|
add_message(WebApiAuth, message_payload)
|
|
request.cls.memory_id = memory_id
|
|
request.cls.agent_ids = agent_ids
|
|
request.cls.session_ids = session_ids
|
|
time.sleep(2) # make sure refresh to index before search
|
|
return memory_id
|