2. Let $x, y, z$ be real numbers, not all zero. Then the maximum value of the function $f(x, y, z)=\frac{x y+y z}{x^{2}+y^{2}+z^{2}}$ is $\qquad$
2. $\frac{\sqrt{2}}{2}$.

Introduce positive parameters $\lambda, \mu$.
Since $\lambda^{2} x^{2}+y^{2} \geqslant 2 \lambda x y, \mu^{2} y^{2}+z^{2} \geqslant 2 \mu y z$. Therefore, $x y \leqslant \frac{\lambda}{2} \cdot x^{2}+\frac{1}{2 \lambda} \cdot y^{2}, y z \leqslant \frac{\mu}{2} \cdot y^{2}+\frac{1}{2 \mu} \cdot z^{2}$.
Adding the two inequalities, we get
$x y+y z \leqslant \frac{\lambda}{2} \cdot x^{2}+\left(\frac{1}{2 \lambda}+\frac{\mu}{2}\right) y^{2}+\frac{1}{2 \mu} \cdot z^{2}$.
Let $\frac{\lambda}{2}=\frac{1}{2 \lambda}+\frac{\mu}{2}=\frac{1}{2 \mu}$, we get $\lambda=\sqrt{2}, \mu=\frac{1}{\sqrt{2}}$.
Thus, $x y+y z \leqslant \frac{\sqrt{2}}{2}\left(x^{2}+y^{2}+z^{2}\right)$.
Therefore, the maximum value of $f(x, y, z)=\frac{x y+y z}{x^{2}+y^{2}+z^{2}}$ is $\frac{\sqrt{2}}{2}$.