Search as Code: What Perplexity's New Architecture Means
Key Points
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.
@aeyespybywinsome This could literally change the internet.
♬ original sound - AEyeSpy
Most AI agents today follow a familiar pattern:
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:
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.
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:
The search strategy itself becomes software.
Rather than selecting from predefined tools, the model creates a custom workflow tailored to the task at hand.
Perplexity describes Search as Code as a three-layer architecture.
The model acts as the planner.
Its responsibilities include:
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.
The generated code executes inside a secure sandbox environment.
Unlike traditional tool-calling systems that rely on stateless API interactions, the sandbox provides:
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.
The third layer exposes Perplexity's search infrastructure as modular building blocks.
These primitives include operations such as:
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.
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.
In a typical agent framework:
The workflow is constrained by the tools developers expose.
The model can choose among available options but cannot fundamentally alter how those tools operate.
With Search as Code:
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.
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:
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:
For organizations deploying large-scale AI agents, these efficiency gains can have meaningful economic implications.
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:
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.
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:
This separation of concerns offers several advantages:
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.
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:
In this future, search becomes less of a black-box service and more of a programmable execution layer.
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.
Key Points
Nothing quite captures Apple's AI predicament like a 4% stock bump for announcing they're finally building what their competitors launched years ago....
Two things happened this week that individually are news. Together, they are a trend worth naming.