4. Given $P_{1}\left(x_{1}, y_{1}\right), P_{2}\left(x_{2}, y_{2}\right), \cdots$, $P_{n}\left(x_{n}, y_{n}\right), \cdots$, where $x_{1}=1, y_{1}=0, x_{n+1}=$ $x_{n}-y_{n}, y_{n+1}=x_{n}+y_{n}\left(n \in \mathbf{Z}_{+}\right)$. If $a_{n}=$ $\overrightarrow{P_{n} P_{n+1}} \cdot \overrightarrow{P_{n+1} P_{n+2}}$, then the smallest positive integer $n$ that satisfies $\sum_{i=1}^{n} a_{i}>1000$ is $n=$ $\qquad$.
4. 10 .

It is known that $\overrightarrow{O P_{n+1}}$ is obtained by rotating $\overrightarrow{O P_{n}}$ counterclockwise by $\frac{\pi}{4}$ and stretching it to $\sqrt{2}$ times its original length.
Thus, $\left|\overrightarrow{P_{n} P_{n+1}}\right|=O P_{n}$,
$\left|\overrightarrow{P_{n+1} P_{n+2}}\right|=\left|O P_{n+1}\right|=\sqrt{2}\left|O P_{n}\right|$.
Therefore, $a_{n}=\left|O P_{n}\right|^{2}=2\left|O P_{n-1}\right|^{2}=2^{n-1}$.
Also, $\sum_{i=1}^{n} a_{i}=2^{n}-1>1000$, hence $n \geqslant 10$.