Repository navigation
Labels
bugSomething isn't working
Description
Describe the bug
On a 6-record dataset containing None values (a is 1 in 4 records and None in 2 records), InMemoryCollection and QdrantCollection both follow 2-valued logic (satisfying complement laws count(A) + count(NOT A) == 6), whereas PostgresCollection emits raw SQL a != 1 / NOT (a = 1), which evaluates to SQL UNKNOWN on NULL rows and drops them:
lambda x: x.a != 1:InMemory=2,Qdrant=2,Postgres=0lambda x: not (x.a == 1):InMemory=2,Qdrant=2,Postgres=0lambda x: not (x.a == 1 and x.b == 1):InMemory=5,Qdrant=5,Postgres=1
To Reproduce
import asyncio
import uuid
from dataclasses import dataclass
from typing import Annotated
from psycopg_pool import AsyncConnectionPool
from semantic_kernel.connectors.in_memory import InMemoryCollection
from semantic_kernel.connectors.postgres import PostgresCollection
from semantic_kernel.connectors.qdrant import QdrantCollection
from semantic_kernel.data.vector import VectorStoreField, vectorstoremodel
PG_URI = "postgresql://diff_user:diff_password@127.0.0.1:5433/agent_persist"
VEC = [1.0, 0.0, 0.0, 0.0]
@vectorstoremodel
@dataclass
class Rec:
id: Annotated[str, VectorStoreField("key")]
vec: Annotated[list[float] | None, VectorStoreField("vector", dimensions=4)] = None
a: Annotated[int | None, VectorStoreField("data", is_indexed=True)] = None
b: Annotated[int | None, VectorStoreField("data", is_indexed=True)] = None
def _r(a, b):
return Rec(id=str(uuid.uuid4()), vec=list(VEC), a=a, b=b)
async def run_backend(name: str, col, pool=None):
docs = [_r(1, 1), _r(1, 0), _r(1, None), _r(1, None), _r(None, 1), _r(None, None)]
f_ne = lambda x: x.a != 1
f_not = lambda x: not (x.a == 1)
f_not_and = lambda x: not (x.a == 1 and x.b == 1)
queries = [("a!=1", f_ne), ("not(a==1)", f_not), ("not(a==1 and b==1)", f_not_and)]
try:
if pool:
await pool.open()
async with col:
await col.ensure_collection_exists()
await col.upsert(docs)
counts = []
for label, flt in queries:
res = await col.search(vector=list(VEC), top=20, filter=flt)
counts.append(f"{label}={len([r async for r in res.results])}")
print(f"{name:<12} | " + " | ".join(counts))
await col.ensure_collection_deleted()
finally:
if pool:
await pool.close()
async def main():
cname = f"t3vl_{uuid.uuid4().hex[:8]}"
await run_backend("InMemory", InMemoryCollection(record_type=Rec, collection_name=cname))
await run_backend("Qdrant", QdrantCollection(record_type=Rec, collection_name=cname, location=":memory:"))
pool = AsyncConnectionPool(conninfo=PG_URI, min_size=1, max_size=2, open=False)
await run_backend("Postgres", PostgresCollection(record_type=Rec, collection_name=cname, connection_pool=pool), pool)
asyncio.run(main())Observed Output
InMemory | a!=1=2 | not(a==1)=2 | not(a==1 and b==1)=5
Qdrant | a!=1=2 | not(a==1)=2 | not(a==1 and b==1)=5
Postgres | a!=1=0 | not(a==1)=0 | not(a==1 and b==1)=1
Expected Behavior
PostgresCollection should match InMemoryCollection and QdrantCollection on != and not (...) over nullable fields:
Postgres | a!=1=2 | not(a==1)=2 | not(a==1 and b==1)=5
Platform
- Python:
3.13.5 semantic-kernel:1.47.0
Activity
prassu017 commentedon Nov 26, 2026
Reproduced on main against a local Postgres 17: the three filters return 0, 0 and 1 rows, versus 2, 2 and 5 in memory. I opened #14899, which uses
IS DISTINCT FROMfor!=andIS NOT TRUEfornot, so Postgres now matches in-memory and Qdrant on all three.