Skip to main content

Code search with Jina Code v2

The Jina Code v2 model is built for semantic code search across 30+ programming languages. It excels at:

  • Finding code snippets from a natural-language description
  • Searching for similar code patterns (even across languages)
  • Linking documentation to code
  • Code-to-code similarity search
note

The snippets below assume you've already created an AI client (and, in Go, a ctx). See Client libraries for connection setup.

1. Create the code store

Use the Jina Code model for both the index and query side, so stored code and your searches land in the same space:

CREATESTORE code_repo QUERYMODEL jina-embeddings-v2-base-code INDEXMODEL jina-embeddings-v2-base-code

2. Index your code snippets

Store each snippet as raw text with a little metadata (language, file). The proxy embeds it with the index model.

Python
from ahnlich_client_py.grpc.ai import query as ai_query
from ahnlich_client_py.grpc import keyval, metadata
from ahnlich_client_py.grpc.ai import preprocess

await client.set(
ai_query.Set(
store="code_repo",
inputs=[
keyval.AiStoreEntry(
key=keyval.StoreInput(
raw_string="fn fibonacci(n: u32) -> u32 { if n <= 1 { n } else { fibonacci(n-1) + fibonacci(n-2) } }"
),
value=keyval.StoreValue(
value={"language": metadata.MetadataValue(raw_string="rust")}
),
),
],
preprocess_action=preprocess.PreprocessAction.ModelPreprocessing,
)
)

3. Search the code store

The query is just raw text — it can be a natural-language description or a code snippet. Same call either way; only the query string changes.

  • Natural language: "implement recursive fibonacci sequence"
  • Code: "def fib(n): return n if n <= 1 else fib(n-1) + fib(n-2)"
Python
from ahnlich_client_py.grpc.ai import query as ai_query
from ahnlich_client_py.grpc import keyval
from ahnlich_client_py.grpc.algorithm import algorithms

response = await client.get_sim_n(
ai_query.GetSimN(
store="code_repo",
search_input=keyval.StoreInput(raw_string="implement recursive fibonacci sequence"),
closest_n=5,
algorithm=algorithms.Algorithm.CosineSimilarity,
)
)

The natural-language query above still surfaces the Rust fibonacci function — semantic code search matches meaning, not exact tokens, so it works across languages.

Use cases

  • Documentation search — index code examples, search them with plain questions.
  • Code discovery — find similar implementations across different languages.
  • Refactoring detection — spot duplicate or near-duplicate patterns.
  • Code review assistance — pull up related snippets for context.
  • IDE integration — power semantic code search in developer tools.