TimeWeightedVectorStoreRetriever keeps documents in memory after vector store insertion fails
Author: Iris070119Created Sep 16, 2026Updated Sep 17, 2026
Labelsbuglangchain-classicexternal
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 typing import Any
from langchain_classic.retrievers.time_weighted_retriever import (
TimeWeightedVectorStoreRetriever,
)
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.vectorstores import VectorStore
class FakeEmbeddings(Embeddings):
def embed_documents(self, texts: list[str]) -> list[list[float]]:
return [[0.0] for _ in texts]
def embed_query(self, text: str) -> list[float]:
return [0.0]
class FailingVectorStore(VectorStore):
@property
def embeddings(self) -> Embeddings:
return FakeEmbeddings()
def add_texts(
self,
texts: list[str],
metadatas: list[dict] | None = None,
**kwargs: Any,
) -> list[str]:
raise RuntimeError("synthetic vector store failure")
def similarity_search(
self,
query: str,
k: int = 4,
**kwargs: Any,
) -> list[Document]:
return []
retriever = TimeWeightedVectorStoreRetriever(
vectorstore=FailingVectorStore(),
)
document = Document(page_content="ghost memory")
try:
retriever.add_documents([document])
except RuntimeError as error:
print(error)
print(
"memory_stream after failure:",
[doc.page_content for doc in retriever.memory_stream],
)
Error Message and Stack Trace (if applicable)
synthetic vector store failure
memory_stream after failure: ['ghost memory']
Description
TimeWeightedVectorStoreRetriever.add_documents() adds documents to
memory_stream before writing them to the vector store.
If vectorstore.add_documents() raises an exception, the method exits while
the documents remain in memory_stream. The retriever therefore contains a
document that was never successfully stored in the vector store.
The relevant order of operations is:
for i, doc in enumerate(dup_docs):
if "last_accessed_at" not in doc.metadata:
doc.metadata["last_accessed_at"] = current_time
if "created_at" not in doc.metadata:
doc.metadata["created_at"] = current_time
doc.metadata["buffer_idx"] = len(self.memory_stream) + i
self.memory_stream.extend(dup_docs)
return self.vectorstore.add_documents(dup_docs, **kwargs)
### 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
Optional packages not installed
-------------------------------
> deepagents
> deepagents-cli
Other Dependencies
------------------
> anyio: 4.15.1
> distro: 1.9.0
> httpx: 0.28.1
> httpx2: 2.13.0
> huggingface-hub: 1.31.0
> jsonpatch: 1.33
> orjson: 3.12.0
> packaging: 26.3
> pydantic: 2.13.5
> pyyaml: 6.0.3
> requests: 2.34.2
> requests-toolbelt: 1.0.0
> sniffio: 1.3.1
> sqlalchemy: 2.0.54
> tenacity: 9.1.4
> tokenizers: 0.23.2
> typing-extensions: 4.16.0
> uuid-utils: 0.17.1
> websockets: 17.1
> xxhash: 4.0.1
> zstandard: 0.25.0
### Social handles (optional)
_No response_
Source: langchain-ai/langchain