A ray is drawn from the origin tangent to the graph of the upper part of the hyperbola $y^2=x^2-x+1$ in the first quadrant.  This ray makes an angle of $\theta$ with the positive $x$-axis.  Compute $\cos\theta$.
1. **Equation of the line**: The line through the origin with slope \( m \) is given by:
   \[
   y = mx
   \]

2. **Substitute into the hyperbola**: Substitute \( y = mx \) into the hyperbola equation \( y^2 = x^2 - x + 1 \):
   \[
   (mx)^2 = x^2 - x + 1
   \]
   Simplifying, we get:
   \[
   m^2 x^2 = x^2 - x + 1
   \]

3. **Form a quadratic equation**: Rearrange the equation to form a quadratic in \( x \):
   \[
   m^2 x^2 - x^2 + x - 1 = 0
   \]
   \[
   (m^2 - 1)x^2 + x - 1 = 0
   \]

4. **Condition for tangency**: For the line to be tangent to the hyperbola, the quadratic equation must have exactly one solution. This occurs when the discriminant is zero. The discriminant \( \Delta \) of the quadratic equation \( ax^2 + bx + c = 0 \) is given by:
   \[
   \Delta = b^2 - 4ac
   \]
   Here, \( a = m^2 - 1 \), \( b = 1 \), and \( c = -1 \). Thus:
   \[
   \Delta = 1^2 - 4(m^2 - 1)(-1)
   \]
   Simplifying, we get:
   \[
   \Delta = 1 - 4(m^2 - 1)(-1) = 1 + 4(m^2 - 1)
   \]
   \[
   \Delta = 1 + 4m^2 - 4
   \]
   \[
   \Delta = 4m^2 - 3
   \]

5. **Set the discriminant to zero**: For tangency, set the discriminant to zero:
   \[
   4m^2 - 3 = 0
   \]
   Solving for \( m^2 \):
   \[
   4m^2 = 3
   \]
   \[
   m^2 = \frac{3}{4}
   \]

6. **Find \( \cos \theta \)**: The slope \( m \) of the line is related to the angle \( \theta \) by \( m = \tan \theta \). We need to find \( \cos \theta \). Using the identity \( \tan^2 \theta + 1 = \sec^2 \theta \), we have:
   \[
   \tan^2 \theta = m^2 = \frac{3}{4}
   \]
   \[
   \sec^2 \theta = 1 + \frac{3}{4} = \frac{7}{4}
   \]
   \[
   \sec \theta = \sqrt{\frac{7}{4}} = \frac{\sqrt{7}}{2}
   \]
   Since \( \sec \theta = \frac{1}{\cos \theta} \), we get:
   \[
   \cos \theta = \frac{2}{\sqrt{7}}
   \]

The final answer is \(\boxed{\frac{2}{\sqrt{7}}}\)