Skip to content

Python: Bug: Python FAISS flat index retains vectors after deleting records #14695

Open

Description

@BlueX888

Describe the bug

Deleting multiple records from the default FAISS flat index can leave vectors behind after their records and key mappings have been removed. Later inserts or searches can then operate on an index that is out of sync with the records.

To Reproduce

Run the following against the Python source at the commit below:

import asyncio
from semantic_kernel.connectors.faiss import FaissCollection
from semantic_kernel.data.vector import VectorStoreCollectionDefinition, VectorStoreField

async def main():
    definition = VectorStoreCollectionDefinition(fields=[
        VectorStoreField("key", name="id"),
        VectorStoreField("data", name="content"),
        VectorStoreField("vector", name="vector", dimensions=2, index_kind="flat", distance_function="dot_prod", type="float"),
    ])
    collection = FaissCollection(record_type=dict, definition=definition, collection_name="test")
    await collection.ensure_collection_exists()
    await collection.upsert([
        {"id": "a", "content": "a", "vector": [1.0, 0.0]},
        {"id": "b", "content": "b", "vector": [0.0, 1.0]},
        {"id": "c", "content": "c", "vector": [1.0, 1.0]},
    ])
    await collection.delete(["a", "b", "c"])
    print("index.ntotal:", collection.indexes["vector"].ntotal)
    print("key map:", collection.indexes_key_map["vector"])

asyncio.run(main())

Actual output:

index.ntotal: 1
key map: {}

Expected behavior

After deleting all three records, the index should contain zero vectors and the key map should be empty.

Platform

  • Language: Python 3.12.2
  • Source: main at 96c9e860db4d7c6da40652d9b421a31b05e98692 (package version 1.46.0)
  • FAISS: 1.13.2
  • OS: Windows, x64
  • AI model / IDE: not applicable

Additional context

IndexFlat.remove_ids shifts the positions of surviving vectors. The collection retains the original offsets for the remaining keys, so a subsequent delete can target a stale position.

This issue is also noted as an existing limitation in #14690, which addresses a separate upsert issue. I would like to work on this deletion bug after discussing a compatible approach, including custom FAISS indexes.

Activity

  1. changed the title [-]Bug: Python FAISS flat index retains vectors after deleting records[/-] [+]Python: Bug: Python FAISS flat index retains vectors after deleting records[/+] on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonPull requests for the Python Semantic Kerneltriage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions