oracle-ai-developer-hub

LangChain Semantic Code Search | Natural-Language Code Retrieval with Oracle VecDB

A full-stack application for semantic code search over a local Python codebase, combining natural-language query understanding, Oracle VecDB retrieval, and interactive file exploration.

πŸš€ Overview

Oracle VecDB acts as the retrieval layer of the application. Parsed code snippets are embedded with a code-aware Jina model, stored as dense vectors together with metadata, and queried at runtime using natural-language search to return relevant functions, classes, and code context.


What you can do with this app

Demo of semantic code search

🧩 Features


🧭 Architecture Flow

  1. The indexing pipeline reads the target Python codebase from CODE_DIR.
  2. Python files are parsed with ast and split into meaningful snippets such as functions, classes, and control-flow blocks.
  3. Each snippet is saved with metadata such as file path, snippet type, and line range.
  4. Code embeddings are generated using the Jina code embedding model.
  5. Snippet vectors and metadata are uploaded into Oracle VecDB.
  6. At query time, the user enters a natural-language description of the code they are looking for.
  7. Oracle VecDB performs top-k similarity search over the indexed code snippets.
  8. The backend returns matched code snippets, metadata, and optional surrounding context for frontend display.

Semantic code search architecture with AST-based snippet extraction, Jina embeddings, Oracle VecDB retrieval, and interactive code exploration.


Why Oracle VecDB in this sample

This sample uses Oracle VecDB as the retrieval backbone for semantic code search. Code snippets are embedded and stored as dense vectors together with metadata, enabling natural-language retrieval over local source files while preserving useful developer context such as file paths, snippet types, and line numbers.


Pre-Installation

Before indexing a codebase, make sure you have a local Python repository available. You can use the LangChain repository as an example, or any other repository of your choice that contains Python files.

git clone https://github.com/langchain-ai/langchain.git

Configuration

Oracle VecDB connection details live in config.py and are loaded from environment variables.


VecDB environment variables

  1. Copy backend/.env.example to backend/.env.
  2. Replace the placeholder VECDB_REST_URL, VECDB_USERNAME, and VECDB_PASSWORD values with your actual VecDB endpoint and credentials.
  3. Keep backend/.env out of source control.

config.py reads these values automatically:

from dotenv import load_dotenv
load_dotenv(override=True)

ORACLE_VECDB_REST_URL = os.getenv("VECDB_REST_URL")
ORACLE_VECDB_USERNAME = os.getenv("VECDB_USERNAME")
ORACLE_VECDB_PASSWORD = os.getenv("VECDB_PASSWORD")
ORACLE_VECDB_ACCESS_TOKEN = os.getenv("VECDB_ACCESS_TOKEN")

You can still override other settings via environment variables, such as ORACLE_TABLE_NAME.


Installation

Backend Setup (FastAPI + Oracle VecDB)

Requirement: Ensure you have Python 3.10+ installed on your machine.

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Before running the backend, do the following:

  1. Navigate to where the LangChain repository had been cloned. This repository contains the codebase through which the app will search.
  2. Navigate to the libs/core/langchain_core directory inside the cloned repository:
cd langchain/libs/core/langchain_core
  1. Copy the absolute path to the langchain_core folder.
  2. Set the CODE_DIR path in your .env file:

Create or edit the .env file in the backend folder of your project and add the following line:

CODE_DIR=/absolute/path/to/langchain/libs/core/langchain_core

Replace with the path that you copied.

  1. Ensure you have python-dotenv installed (already included in the backend requirements).
  2. Run load_chunks.py to chunk and upsert the codebase into Oracle VecDB. NOTE: This may take a few minutes to complete and requires access to the configured Oracle VecDB endpoint.

Frontend Setup (React)

cd frontend
npm install

Running the Application

Launch Backend (FastAPI)

uvicorn main:app --host 0.0.0.0 --port 8000

Ensure that the Oracle VecDB connection values are correctly set in your environment variables or in config.py.

Launch Frontend (React)

VITE_API_BASE=http://<vm_ip_addrs>:8000 npm run dev -- --host 0.0.0.0 --port 5178

The frontend will run at: http://<vm_ip_addrs>:5178


Quickstart

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python load_chunks.py
uvicorn main:app --host 0.0.0.0 --port 8000

Project Structure

semantic_code_search/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ .env.example
β”‚   β”œβ”€β”€ config.py
β”‚   β”œβ”€β”€ load_chunks.py
β”‚   β”œβ”€β”€ main.py
β”‚   └── requirements.txt
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ App.tsx
β”‚   β”‚   β”œβ”€β”€ SearchInterface.tsx
β”‚   β”‚   β”œβ”€β”€ CodeViewer.tsx
β”‚   β”‚   └── VectorDBInfo.tsx
β”‚   └── package.json
β”œβ”€β”€ images/
β”‚   └── screenshot.png
└── README.md

Vector Database Configuration (Oracle VecDB)


Stored Metadata

Each indexed code snippet stores metadata such as:

This metadata allows the frontend to present search results together with file locations and surrounding code context.


Embedding Model & Vector Integration


Indexing Pipeline

Parsed Snippet File

Relevant Fields

Workflow

  1. Traverse the Python codebase recursively and identify all .py files.
  2. Parse each Python file using ast and extract semantically meaningful code snippets (functions, classes, if-blocks, etc.).
  3. Store these snippets with metadata in a .jsonl file.
  4. Generate vector embeddings using the jinaai/jina-embeddings-v2-base-code model.
  5. Upsert embeddings and metadata into Oracle VecDB using the oracle_vecdb SDK.
  6. Enable similarity-based search by querying Oracle VecDB directly from the FastAPI backend.

Query Flow

  1. The user submits a natural-language query from the frontend.
  2. The backend generates a query embedding using the Jina code embedding model.
  3. Oracle VecDB performs top-k similarity search over indexed code snippets.
  4. Matching snippets are returned together with metadata and optional surrounding context.
  5. The frontend renders results and allows the user to inspect file contents and reveal additional lines.

πŸ–ΌοΈ UI Image

Semantic code search UI with natural-language query input, top-k retrieval, vector DB info, and interactive file browsing.


Current Limitations


Developer Enablement Context

This sample is designed to demonstrate how Oracle VecDB can support semantic retrieval over source code, combining code embeddings, metadata-aware indexing, and natural-language developer search workflows in an end-to-end application.