mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2026-01-02 17:46:56 +00:00
feat(docs): update architecture docs
This commit is contained in:
@@ -1,11 +1,38 @@
|
|||||||
# Perplexica's Architecture
|
# Perplexica Architecture
|
||||||
|
|
||||||
Perplexica's architecture consists of the following key components:
|
Perplexica is a Next.js application that combines an AI chat experience with search.
|
||||||
|
|
||||||
1. **User Interface**: A web-based interface that allows users to interact with Perplexica for searching images, videos, and much more.
|
For a high level flow, see [WORKING.md](WORKING.md). For deeper implementation details, see [CONTRIBUTING.md](../../CONTRIBUTING.md).
|
||||||
2. **Agent/Chains**: These components predict Perplexica's next actions, understand user queries, and decide whether a web search is necessary.
|
|
||||||
3. **SearXNG**: A metadata search engine used by Perplexica to search the web for sources.
|
|
||||||
4. **LLMs (Large Language Models)**: Utilized by agents and chains for tasks like understanding content, writing responses, and citing sources. Examples include Claude, GPTs, etc.
|
|
||||||
5. **Embedding Models**: To improve the accuracy of search results, embedding models re-rank the results using similarity search algorithms such as cosine similarity and dot product distance.
|
|
||||||
|
|
||||||
For a more detailed explanation of how these components work together, see [WORKING.md](https://github.com/ItzCrazyKns/Perplexica/tree/master/docs/architecture/WORKING.md).
|
## Key components
|
||||||
|
|
||||||
|
1. **User Interface**
|
||||||
|
|
||||||
|
- A web based UI that lets users chat, search, and view citations.
|
||||||
|
|
||||||
|
2. **API Routes**
|
||||||
|
|
||||||
|
- `POST /api/chat` powers the chat UI.
|
||||||
|
- `POST /api/search` provides a programmatic search endpoint.
|
||||||
|
- `GET /api/providers` lists available providers and model keys.
|
||||||
|
|
||||||
|
3. **Agents and Orchestration**
|
||||||
|
|
||||||
|
- The system classifies the question first.
|
||||||
|
- It can run research and widgets in parallel.
|
||||||
|
- It generates the final answer and includes citations.
|
||||||
|
|
||||||
|
4. **Search Backend**
|
||||||
|
|
||||||
|
- A meta search backend is used to fetch relevant web results when research is enabled.
|
||||||
|
|
||||||
|
5. **LLMs (Large Language Models)**
|
||||||
|
|
||||||
|
- Used for classification, writing answers, and producing citations.
|
||||||
|
|
||||||
|
6. **Embedding Models**
|
||||||
|
|
||||||
|
- Used for semantic search over user uploaded files.
|
||||||
|
|
||||||
|
7. **Storage**
|
||||||
|
- Chats and messages are stored so conversations can be reloaded.
|
||||||
|
|||||||
@@ -1,19 +1,72 @@
|
|||||||
# How does Perplexica work?
|
# How Perplexica Works
|
||||||
|
|
||||||
Curious about how Perplexica works? Don't worry, we'll cover it here. Before we begin, make sure you've read about the architecture of Perplexica to ensure you understand what it's made up of. Haven't read it? You can read it [here](https://github.com/ItzCrazyKns/Perplexica/tree/master/docs/architecture/README.md).
|
This is a high level overview of how Perplexica answers a question.
|
||||||
|
|
||||||
We'll understand how Perplexica works by taking an example of a scenario where a user asks: "How does an A.C. work?". We'll break down the process into steps to make it easier to understand. The steps are as follows:
|
If you want a component level overview, see [README.md](README.md).
|
||||||
|
|
||||||
1. The message is sent to the `/api/chat` route where it invokes the chain. The chain will depend on your focus mode. For this example, let's assume we use the "webSearch" focus mode.
|
If you want implementation details, see [CONTRIBUTING.md](../../CONTRIBUTING.md).
|
||||||
2. The chain is now invoked; first, the message is passed to another chain where it first predicts (using the chat history and the question) whether there is a need for sources and searching the web. If there is, it will generate a query (in accordance with the chat history) for searching the web that we'll take up later. If not, the chain will end there, and then the answer generator chain, also known as the response generator, will be started.
|
|
||||||
3. The query returned by the first chain is passed to SearXNG to search the web for information.
|
|
||||||
4. After the information is retrieved, it is based on keyword-based search. We then convert the information into embeddings and the query as well, then we perform a similarity search to find the most relevant sources to answer the query.
|
|
||||||
5. After all this is done, the sources are passed to the response generator. This chain takes all the chat history, the query, and the sources. It generates a response that is streamed to the UI.
|
|
||||||
|
|
||||||
## How are the answers cited?
|
## What happens when you ask a question
|
||||||
|
|
||||||
The LLMs are prompted to do so. We've prompted them so well that they cite the answers themselves, and using some UI magic, we display it to the user.
|
When you send a message in the UI, the app calls `POST /api/chat`.
|
||||||
|
|
||||||
## Image and Video Search
|
At a high level, we do three things:
|
||||||
|
|
||||||
Image and video searches are conducted in a similar manner. A query is always generated first, then we search the web for images and videos that match the query. These results are then returned to the user.
|
1. Classify the question and decide what to do next.
|
||||||
|
2. Run research and widgets in parallel.
|
||||||
|
3. Write the final answer and include citations.
|
||||||
|
|
||||||
|
## Classification
|
||||||
|
|
||||||
|
Before searching or answering, we run a classification step.
|
||||||
|
|
||||||
|
This step decides things like:
|
||||||
|
|
||||||
|
- Whether we should do research for this question
|
||||||
|
- Whether we should show any widgets
|
||||||
|
- How to rewrite the question into a clearer standalone form
|
||||||
|
|
||||||
|
## Widgets
|
||||||
|
|
||||||
|
Widgets are small, structured helpers that can run alongside research.
|
||||||
|
|
||||||
|
Examples include weather, stocks, and simple calculations.
|
||||||
|
|
||||||
|
If a widget is relevant, we show it in the UI while the answer is still being generated.
|
||||||
|
|
||||||
|
Widgets are helpful context for the answer, but they are not part of what the model should cite.
|
||||||
|
|
||||||
|
## Research
|
||||||
|
|
||||||
|
If research is needed, we gather information in the background while widgets can run.
|
||||||
|
|
||||||
|
Depending on configuration, research may include web lookup and searching user uploaded files.
|
||||||
|
|
||||||
|
## Answer generation
|
||||||
|
|
||||||
|
Once we have enough context, the chat model generates the final response.
|
||||||
|
|
||||||
|
You can control the tradeoff between speed and quality using `optimizationMode`:
|
||||||
|
|
||||||
|
- `speed`
|
||||||
|
- `balanced`
|
||||||
|
- `quality`
|
||||||
|
|
||||||
|
## How citations work
|
||||||
|
|
||||||
|
We prompt the model to cite the references it used. The UI then renders those citations alongside the supporting links.
|
||||||
|
|
||||||
|
## Search API
|
||||||
|
|
||||||
|
If you are integrating Perplexica into another product, you can call `POST /api/search`.
|
||||||
|
|
||||||
|
It returns:
|
||||||
|
|
||||||
|
- `message`: the generated answer
|
||||||
|
- `sources`: supporting references used for the answer
|
||||||
|
|
||||||
|
You can also enable streaming by setting `stream: true`.
|
||||||
|
|
||||||
|
## Image and video search
|
||||||
|
|
||||||
|
Image and video search use separate endpoints (`POST /api/images` and `POST /api/videos`). We generate a focused query using the chat model, then fetch matching results from a search backend.
|
||||||
|
|||||||
Reference in New Issue
Block a user