This is a part of the geometric definition, but originally comes from the algebraic definition (see here)
In Euclidean space, you have to define a vector. With that vector, following the algebraic definition
$\vec{a} \cdot \vec{b} = \sum_i a_i b_i$
Imagine at the origin you have two vectors, pointing from $O$ to $A = (a_i)_{i=1}^n$ and to $B = (b_i)_{i=1}^n$. You can pick $n=2,3$ for the sake of imagination.
Now drop a perpendicular line from $B = (b_i)_{i=1}^n$ onto $OA$, crossing $OA$ at a point, called $H$. Let $\theta$ be the angle $(OA,OB)$. After a long calculation, the length of $OH$ is $\frac{\sum_i a_i b_i}{||a||} $.
Observe that $\cos \theta = \frac{|OH|}{|OB|}$, you now arrive at the formula
$\cos \theta = \frac{\vec{a}\cdot \vec{b}} {||a|| \cdot ||b||}$