4 min read

Perplexity Search as Code: A New Way to Search

Perplexity Search as Code: A New Way to Search

Perplexity recently introduced Search as Code (SaC), a new architecture that fundamentally changes how AI models interact with search systems. Rather than relying on traditional search APIs, Search as Code allows AI models to generate and execute custom search workflows in Python.

While the announcement may sound like another incremental improvement in AI tooling, the underlying architectural shift is significant. Search as Code moves retrieval orchestration away from fixed API endpoints and into executable code generated by the model itself.

According to Perplexity's research, this approach achieved up to 85% lower token consumption while significantly improving performance on complex research benchmarks.

For developers building AI agents, autonomous research systems, and retrieval-augmented generation (RAG) applications, Search as Code may represent an important glimpse into the future of agent architecture.

The Problem With Traditional AI Search Workflows

Most AI agents today follow a familiar pattern:

  1. The model generates a search query.
  2. A search API returns results.
  3. The model reads those results.
  4. The model generates another query.
  5. The process repeats until an answer is produced.

This workflow works reasonably well for simple retrieval tasks, but it creates several limitations when agents must conduct complex research.

The model can control the query itself, but it typically has little influence over how results are:

  • Ranked
  • Filtered
  • Deduplicated
  • Parsed
  • Aggregated
  • Re-ranked

Those decisions remain hidden inside the search engine.

In other words, the model can request information but cannot directly control the retrieval pipeline responsible for gathering that information.

This becomes especially problematic for agentic workflows that require hundreds of searches, cross-source verification, structured data extraction, and iterative reasoning.

What Is Search as Code?

Search as Code replaces traditional API-driven search with model-generated executable workflows.

Instead of issuing a query such as:

"Find high-severity vulnerabilities affecting Cisco products."

The model writes Python code that constructs an entire retrieval strategy.

That code can:

  • Execute multiple searches simultaneously
  • Fan out queries across multiple sources
  • Extract specific data fields
  • Remove duplicates
  • Apply custom ranking logic
  • Trigger follow-up searches automatically
  • Persist intermediate results

The search strategy itself becomes software.

Rather than selecting from predefined tools, the model creates a custom workflow tailored to the task at hand.

Understanding the Three Layers of Search as Code

Perplexity describes Search as Code as a three-layer architecture.

1. The Model (Control Plane)

The model acts as the planner.

Its responsibilities include:

  • Understanding the user request
  • Decomposing the problem
  • Designing a retrieval strategy
  • Generating executable Python code

Instead of deciding only which keywords to search, the model determines how information should be gathered, processed, and validated.

This represents a significant expansion of model responsibility.

2. The Compute Sandbox

The generated code executes inside a secure sandbox environment.

Unlike traditional tool-calling systems that rely on stateless API interactions, the sandbox provides:

  • Persistent storage
  • Cross-turn memory
  • File-system access
  • Serialized intermediate state

This design allows research tasks to span multiple execution cycles without repeatedly loading information into the model's context window.

As research tasks become more complex, this persistence becomes increasingly valuable.

3. Agentic Search SDK

The third layer exposes Perplexity's search infrastructure as modular building blocks.

These primitives include operations such as:

  • Retrieve
  • Fanout
  • Filter
  • Deduplicate
  • Rerank
  • Parse fields

Instead of interacting with a monolithic search API, generated code can combine these primitives in virtually unlimited ways.

The result is a highly flexible retrieval architecture that can adapt to different research tasks dynamically.

Why Search as Code Is Different From Function Calling

Many modern AI systems already support tools and function calling.

At first glance, Search as Code may appear similar.

However, there is an important distinction.

Traditional Function Calling

In a typical agent framework:

  • The model selects a tool
  • The tool executes predefined behavior
  • Results return to the model

The workflow is constrained by the tools developers expose.

The model can choose among available options but cannot fundamentally alter how those tools operate.

Search as Code

With Search as Code:

  • The model writes executable code
  • The code creates the workflow
  • The workflow determines how retrieval occurs

This shifts the paradigm from tool selection to program synthesis.

Instead of choosing from a menu of capabilities, the model constructs new retrieval pipelines dynamically.

That distinction may prove increasingly important as AI agents tackle more sophisticated research tasks.

Why Search as Code Uses Fewer Tokens

One of Perplexity's most notable findings was a reported 85% reduction in token consumption compared to traditional search workflows.

This improvement stems from where processing occurs.

In many current agent architectures:

  • Search results are returned to the LLM
  • The LLM filters irrelevant information
  • The LLM extracts useful details
  • The LLM determines what to keep

Every one of these operations consumes tokens.

Search as Code moves much of that work into executable code.

Filtering, aggregation, and ranking happen inside the runtime rather than inside the model.

The result is:

  • Less context window bloat
  • Fewer repeated searches
  • Reduced token usage
  • Faster execution
  • Lower operating costs

For organizations deploying large-scale AI agents, these efficiency gains can have meaningful economic implications.

Benchmark Results: Accuracy Improvements Across Research Tasks

Perplexity evaluated Search as Code on several research-oriented benchmarks.

One notable case study involved identifying approximately 200 high-severity Common Vulnerabilities and Exposures (CVEs) spanning multiple years and vendor-specific advisory formats.

According to Perplexity:

  • Search as Code achieved 100% accuracy
  • Traditional approaches consumed substantially more tokens
  • Competing systems scored significantly lower on the same task

Additional benchmarks reportedly showed strong improvements across broad research workloads, including substantial gains on WANDR and DSQA evaluations.

While independent validation will be important, the early results suggest that retrieval architecture may be becoming as important as model capability itself.

The Bigger Trend: Models Generating Workflows Instead of Calling Tools

Search as Code reflects a broader movement occurring throughout AI.

Historically, large language models have acted primarily as interfaces to external tools.

The emerging pattern looks different:

  • Models perform reasoning
  • Code performs execution
  • Deterministic systems handle scale
  • Infrastructure becomes programmable

This separation of concerns offers several advantages:

  • Better efficiency
  • Improved reliability
  • Greater transparency
  • More sophisticated planning

Rather than repeatedly invoking APIs, models increasingly generate programs that interact with infrastructure on their behalf.

This is similar to trends seen across autonomous agents, coding systems, and computer-use platforms.

What Search as Code Means for Developers

For developers building AI-powered applications, Search as Code introduces an important architectural question:

Should models use tools, or should they generate workflows?

The answer may increasingly be both.

Search APIs are unlikely to disappear, but developers may begin demanding access to lower-level primitives that models can orchestrate directly.

This could push search providers toward exposing:

  • Retrieval primitives
  • Ranking primitives
  • Filtering primitives
  • Structured extraction capabilities
  • Workflow composition frameworks

In this future, search becomes less of a black-box service and more of a programmable execution layer.

Final Thoughts

Search as Code is more than a search feature.

It represents a shift in how AI systems interact with infrastructure.

By allowing models to generate executable search pipelines instead of relying solely on fixed APIs, Perplexity is moving retrieval closer to software engineering and further away from traditional search interfaces.

Whether Search as Code becomes the dominant pattern remains to be seen. However, the underlying principle is likely to persist:

The most capable AI systems of the future may not simply use tools.

They may build their own workflows dynamically, using code as the bridge between reasoning and execution.

As AI agents become more autonomous, that architectural shift could prove just as important as the next breakthrough model.