4. As shown in Figure 3, in Rt $\triangle A B C$, $C D$ and $C E$ are the altitude and median to the hypotenuse $A B$, respectively, $B C = a, A C = b (b > a)$. If $\tan \angle D C E = \frac{1}{3}$, then $\frac{a}{b}=$ $\qquad$
4. $\frac{\sqrt{10}-1}{3}$.

It is known that, $C D=\frac{a b}{\sqrt{a^{2}+b^{2}}}$.
By the projection theorem, we have
$$
\begin{array}{l}
B C^{2}=B D \cdot B A \\
\Rightarrow B D=\frac{B C^{2}}{B A}=\frac{a^{2}}{\sqrt{a^{2}+b^{2}}} \\
\Rightarrow D E=B E-B D=\frac{b^{2}-a^{2}}{2 \sqrt{a^{2}+b^{2}}} \\
\Rightarrow \tan \angle D C E=\frac{D E}{C D} \\
\quad \frac{\frac{b^{2}-a^{2}}{2 \sqrt{a^{2}+b^{2}}}}{\frac{a b}{\sqrt{a^{2}+b^{2}}}}=\frac{1}{3} .
\end{array}
$$

Therefore, $\frac{a}{b}=\frac{\sqrt{10}-1}{3}$ (negative value is discarded).