add param to set query timeout when do vector/full-text search

pull/18613/head
jiangzhijie 1 year ago
parent cf464d252d
commit e581c8b70a

@ -297,6 +297,7 @@ LINDORM_URL=http://ld-*******************-proxy-search-pub.lindorm.aliyuncs.com:
LINDORM_USERNAME=admin LINDORM_USERNAME=admin
LINDORM_PASSWORD=admin LINDORM_PASSWORD=admin
USING_UGC_INDEX=False USING_UGC_INDEX=False
QUERY_TIMEOUT=1
# OceanBase Vector configuration # OceanBase Vector configuration
OCEANBASE_VECTOR_HOST=127.0.0.1 OCEANBASE_VECTOR_HOST=127.0.0.1

@ -32,3 +32,8 @@ class LindormConfig(BaseSettings):
description="Using UGC index will store the same type of Index in a single index but can retrieve separately.", description="Using UGC index will store the same type of Index in a single index but can retrieve separately.",
default=False, default=False,
) )
QUERY_TIMEOUT: Optional[float] = Field(
description="The lindorm search request timeout (s)",
default=2.0
)

@ -32,6 +32,7 @@ class LindormVectorStoreConfig(BaseModel):
username: Optional[str] = None username: Optional[str] = None
password: Optional[str] = None password: Optional[str] = None
using_ugc: Optional[bool] = False using_ugc: Optional[bool] = False
request_timeout: Optional[float] = 1.0 # timeout units: s
@model_validator(mode="before") @model_validator(mode="before")
@classmethod @classmethod
@ -251,7 +252,7 @@ class LindormVectorStore(BaseVector):
query = default_vector_search_query(query_vector=query_vector, k=top_k, filters=filters, **kwargs) query = default_vector_search_query(query_vector=query_vector, k=top_k, filters=filters, **kwargs)
try: try:
params = {} params = {"timeout": self._client_config.request_timeout}
if self._using_ugc: if self._using_ugc:
params["routing"] = self._routing params["routing"] = self._routing
response = self._client.search(index=self._collection_name, body=query, params=params) response = self._client.search(index=self._collection_name, body=query, params=params)
@ -304,8 +305,8 @@ class LindormVectorStore(BaseVector):
routing=routing, routing=routing,
routing_field=self._routing_field, routing_field=self._routing_field,
) )
params = {"timeout": self._client_config.request_timeout}
response = self._client.search(index=self._collection_name, body=full_text_query) response = self._client.search(index=self._collection_name, body=full_text_query, params=params)
docs = [] docs = []
for hit in response["hits"]["hits"]: for hit in response["hits"]["hits"]:
docs.append( docs.append(
@ -554,6 +555,7 @@ class LindormVectorStoreFactory(AbstractVectorFactory):
username=dify_config.LINDORM_USERNAME, username=dify_config.LINDORM_USERNAME,
password=dify_config.LINDORM_PASSWORD, password=dify_config.LINDORM_PASSWORD,
using_ugc=dify_config.USING_UGC_INDEX, using_ugc=dify_config.USING_UGC_INDEX,
request_timeout=dify_config.QUERY_TIMEOUT
) )
using_ugc = dify_config.USING_UGC_INDEX using_ugc = dify_config.USING_UGC_INDEX
if using_ugc is None: if using_ugc is None:

@ -553,6 +553,7 @@ VIKINGDB_SOCKET_TIMEOUT=30
LINDORM_URL=http://lindorm:30070 LINDORM_URL=http://lindorm:30070
LINDORM_USERNAME=lindorm LINDORM_USERNAME=lindorm
LINDORM_PASSWORD=lindorm LINDORM_PASSWORD=lindorm
QUERY_TIMEOUT=1
# OceanBase Vector configuration, only available when VECTOR_STORE is `oceanbase` # OceanBase Vector configuration, only available when VECTOR_STORE is `oceanbase`
OCEANBASE_VECTOR_HOST=oceanbase OCEANBASE_VECTOR_HOST=oceanbase

Loading…
Cancel
Save