InMemoryVectorStore.delete(None) 不会删除所有文档
作者: Iris070119创建于 2026年9月16日更新于 2026年9月17日
标签bugcoreexternal
Submission checklist
- This is a bug, not a usage question.
- I added a clear and descriptive title that summarizes this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
- This is not related to the LangChain-community package.
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Package (Required)
- LangChain
- LangChain-OpenAI
- LangChain-Anthropic
- LangChain-classic
- LangChain-core
- LangChain-model-profiles
- LangChain-tests
- LangChain-text-splitters
- LangChain-chroma
- LangChain-DeepSeek
- LangChain-exa
- LangChain-fireworks
- LangChain-groq
- LangChain-huggingface
- LangChain-mistralai
- LangChain-nomic
- LangChain-ollama
- LangChain-openrouter
- LangChain-Perplexity
- LangChain-qdrant
- LangChain-xai
- Other / not sure / general
Related Issues / PRs
No response
Reproduction Steps / Example Code (Python)
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.vectorstores import InMemoryVectorStore
class FakeEmbeddings(Embeddings):
def embed_documents(self, texts: list[str]) -> list[list[float]]:
return [[1.0, 0.0] for _ in texts]
def embed_query(self, text: str) -> list[float]:
return [1.0, 0.0]
vectorstore = InMemoryVectorStore(FakeEmbeddings())
vectorstore.add_documents(
[Document(page_content="document A")],
ids=["doc-a"],
)
print("IDs before delete:", list(vectorstore.store))
vectorstore.delete(ids=None)
print("IDs after delete:", list(vectorstore.store))
Error Message and Stack Trace (if applicable)
Description
VectorStore.delete() documents that passing ids=None should delete all
vectors. However, InMemoryVectorStore.delete() only performs deletion when
ids is truthy.
The implementation currently uses:
def delete(
self,
ids: Sequence[str] | None = None,
**kwargs: Any,
) -> None:
if ids:
for identifier in ids:
self.store.pop(identifier, None)
### System Info
System Information
------------------
> OS: Windows
> OS Version: 10.0.26200
> Python Version: 3.13.3 (main, May 30 2025, 05:37:00) [MSC v.1943 64 bit (AMD64)]
Package Information
-------------------
> langchain_core: 1.6.3
> langsmith: 0.12.5
> langchain_classic: 1.0.8
> langchain_huggingface: 1.2.2
> langchain_protocol: 0.0.19
> langchain_text_splitters: 1.1.2
内容来源: langchain-ai/langchain