Issue,迭代交叉KV(NoSql/Redis)Target

问题描述 投票:0回答:2

我也想在 MLRun 中迭代交叉 KV(NoSql,Redis)目标而不指定主键,但我看到只能根据特定键获取特定 KV 项。我必须只使用独特的物品,而不是重复的物品。

我选择 NoSql/Redis Target 是因为内存中的键操作对于快速响应(基于特定键)至关重要,但有时我必须遍历整个键集合(这就是这个问题的情况)。

你可以看到我根据键获取值的部分代码:

import mlrun 
import mlrun.feature_store as fs
...

svc=fs.get_online_feature_service(fs.FeatureVector("myVector", ["client.*"]))
resp = svc.get([{"cuid": 1926, "key1": 100023}])

你知道吗,如何在 MLRun(版本 1.2.1)中迭代 KV(NoSql、Redis)目标中的交叉项?

python redis nosql mlops mlrun
2个回答
1
投票

NoSqlTarget
使用的是 KV 存储,它本质上是用于根据给定的键检索单个值。如果您希望检索整个特征向量,则应改用离线商店。 MLRun 文档中的更多信息这里

或者,您可以使用离线商店获取密钥列表,然后使用这些查询在线商店:

import mlrun.feature_store as fstore

df = fstore.get_offline_features("my-vec").to_dataframe()
keys = list(resp.to_dataframe().index.unique())

svc = fstore.get_online_feature_service("my-vec")
svc.get([{"my-key" : key} for key in keys[:5]])

1
投票

我正在使用这些解决方案进行迭代交叉 KV:

1。 NoSqlTarget

通过 v3io 进行迭代(它不是 MLRun API 的纯粹部分,而是 MLRun 分发包的一部分)。有关 v3io python SDK 的更多信息 see 和迭代交叉 KV 项(游标用法)see sample

import v3io.dataplane

v3io_client = v3io.dataplane.Client(endpoint='https://v3io-webapi:8081', access_key='some_access_key')

# create a query, and use an items cursor to iterate the results
items_cursor = v3io_client.kv.new_cursor(container='users',
                                         table_path='/user-profile',
                                         attribute_names=['income'],
                                         filter_expression='income > 150')

# print the output
for item in items_cursor.all():
    print(item)

2。 RedisTarget

您可以使用简单的迭代交叉 KV 项,它是 Redis API 的一部分

import redis

r = redis.StrictRedis(host='localhost', port=6379, db=0)
for key in r.keys('*'):
    r.delete(key)

顺便说一句:也可以通过

redis-cli

使用命令行
© www.soinside.com 2019 - 2024. All rights reserved.