diff --git a/libs/experimental/langchain_experimental/text_splitter.py b/libs/experimental/langchain_experimental/text_splitter.py index 02e7d80916e..be3a795b06a 100644 --- a/libs/experimental/langchain_experimental/text_splitter.py +++ b/libs/experimental/langchain_experimental/text_splitter.py @@ -180,7 +180,11 @@ class SemanticChunker(BaseDocumentTransformer): x = max(min(self.number_of_chunks, x1), x2) # Linear interpolation formula - y = y1 + ((y2 - y1) / (x2 - x1)) * (x - x1) + if x2 == x1: + y = y2 + else: + y = y1 + ((y2 - y1) / (x2 - x1)) * (x - x1) + y = min(max(y, 0), 100) return cast(float, np.percentile(distances, y))