agentscope-ai / agentscope-ai/agentscope

Long Memory with ReMe using custom pgvector: asyncpg fails with "could not determine data type of parameter $2" when using metadata filters

未关闭
#1,062 2 条评论 0 个 reaction 已指派 1 人 已被 @jinliyl 认领 在 GitHub 查看
stale-issue
主要语言
Python
星标
31.5k
派生
3.5k
平均合并
1 天 23 小时
30 天内合并 PR
95

描述

## Description

When using `PgVectorStore` with asyncpg and metadata filters (e.g., in `load_today_memory_op`), the query fails with:

```
Error retrieving today's memories: could not determine data type of parameter $2
```

## Environment

- flowllm version: 0.2.0.8
- reme-ai version: 0.2.0.4
- PostgreSQL: Supabase (pgvector enabled), connected with session pooler
- Python: 3.12

## Steps to Reproduce

1. Use `ReMePersonalLongTermMemory` with pgvector backend:

```python
from agentscope.memory import ReMePersonalLongTermMemory

long_term_memory = ReMePersonalLongTermMemory(
agent_name="Friday",
user_name=user_id,
model=model,
embedding_model=embedding_model,
**{
"vector_store.default.backend": "pgvector",
}
)
```

2. Record some memories
3. On next query, `load_today_memory_op` attempts to retrieve today's memories with filter:

```python
filter_dict = {
"memory_type": "personal",
"target": user_name,
"created_date": "20251227"
}
```

4. The async search fails with the error above

## Error Log

```
2025-12-27 17:06:59 | ERROR | load_today_memory_op.py:103 | Error retrieving today's memories: could not determine data type of parameter $2
```

## Root Cause

In `pgvector_vector_store.py`, the `async_search` method at line 704:

```python
rows = await conn.fetch(query_sql, query_vector_str, *filter_params, top_k)
```

The generated SQL has filters like:

```sql
WHERE metadata->>'memory_type' = $2 AND metadata->>'target' = $3 AND metadata->>'created_date' = $4
```

**The problem:** asyncpg requires explicit type casting for parameters when comparing with JSONB extracted text (`->>`). The `filter_params` are Python strings, but asyncpg cannot infer the PostgreSQL type for the comparison.

This is a known behavior difference between psycopg and asyncpg - psycopg handles type inference more leniently, while asyncpg is strict.

## Impact

- **Affected functionality:** `load_today_memory_op` fails silently, returning empty results
- **Workaround:** None - the error is caught and handled gracefully, but the "today's memories" deduplication feature is broken

## Relevant Code Locations

| File | Lines | Function |
|------|-------|----------|
| `flowllm/core/vector_store/pgvector_vector_store.py` | 287-360 | `_build_sql_filters` |
| `flowllm/core/vector_store/pgvector_vector_store.py` | 637-736 | `async_search` |
| `reme_ai/summary/personal/load_today_memory_op.py` | 77-81 | `_retrieve_today_memories` |

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。