def build_localised_splits(
        self,
        chunks: List[str],
    ) -> List[Dict[str, str]]:
        """Generate localized context for each chunk using a sliding window approach."""
        half_window = self.window_size // 2
        localized_splits = []
        for i in range(len(chunks)):
            start = max(0, i - half_window)
            end = min(len(chunks), i + half_window + 1)
            window_chunk = " ".join(chunks[start:end])

            # format prompt with current chunk and window chunk
            llm_messages = [
                ChatMessage(role="system", content=CONTEXT_GENERATION_SYSTEM_PROMPT),
                ChatMessage(
                    role="user",
                    content=CONTEXT_GENERATION_USER_PROMPT.format(
                        window_chunk=window_chunk, chunk=chunks[i]
                    ),
                ),
            ]

            # generate localized context using LLM
            localized_context = str(self.llm.chat(messages=llm_messages))
            localized_splits.append(
                {
                    "text": chunks[i],
                    "context": localized_context,
                }
            )

        return localized_splits
Generate localized context for each chunk using a sliding window approach.
llama-index-integrations/node_parser/llama-index-node-parser-slide/llama_index/node_parser/slide/base.py