> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pawa-ai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Semantic Retrieval

> Pawa AI helps find relevant documents and information using natural language queries instead of exact keyword matches.

Semantic retrieval finds relevant information by understanding the meaning behind your query, not just matching keywords. It uses embeddings to search through your knowledge base and return the most contextually relevant documents.

Pawa AI make implement advanced mathematics that make it ease  and accurate for you to search exactly the simmilar informations on the documents by just sending request to our api

> **Semantic Retrieval Example**

<img src="https://mintcdn.com/sartifycoltd/h3QvoufTX15l3Mnz/images/Semantic%20Retrieval.png?fit=max&auto=format&n=h3QvoufTX15l3Mnz&q=85&s=28a1d9a1b006b18149197beebc92ce64" alt="Semantic Retrieval Example" className="w-full" width="1932" height="1216" data-path="images/Semantic Retrieval.png" />

### How it works

1. **Index your documents** into Pawa AI's knowledge base
2. **Query with natural language** - ask questions in plain English or Swahili
3. **Get ranked results** - most relevant documents appear first based on semantic similarity
4. **Use in RAG** or elsewhere - feed retrieved context to chat models for grounded answers

<Note>
  This is the **FREE** endpoint, not cost associated with it. After creating knowledge base with Pawa AI , you can use the retrieval endpoint to get the top-k relevant results, that can be used in your RAG or else use cases.
</Note>

### What you can build

* **Intelligent search** across documents, PDFs, and knowledge bases
* **Question answering** systems that find relevant context
* **Content recommendations** based on semantic similarity
* **Document discovery** for large repositories
* **Customer support** with instant access to relevant help articles

### Using Pawa AI Knowledge Base

Pawa AI provides a managed knowledge base with built-in semantic retrieval. Upload your documents and query them naturally.

To learn more knowledge base in Pawa AI, see [here](/capabilities/knowledge-base).

#### 1. Create a Knowledge Base & Upload documents

```bash theme={null}
  curl --request POST \
  --url https://api.pawa-ai.com/v1/store/knowledge-base \
  --header "Authorization: Bearer $PAWA_AI_API_KEY" \
  --header 'Content-Type: multipart/form-data' \
  --form 'name=WCF Knowledgebase' \
  --form 'description=This is the knowledgebase about WCF (Workers compensation fund) in Tanzania......etc...' \
  --form knowledgeBase=@67f22be974bbec7dacd9cfdb.pdf
```

#### 2. Semantic Search across your knowledge

```bash theme={null}
  curl --request POST \
  --url https://api.pawa-ai.com/v1/store/knowledge-base/semantic-retrieval \
  --header "Authorization: Bearer $PAWA_AI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "knowledge_base_id": "23",
  "question_asked_by_user": "When WCF got started?"
}'
```

### Response Format Example

```json theme={null}
{
  "finalRelevantChunk": [
    "Hello Pawa AI, I am the final relevant chunk you need"
  ],
  "filteredResults": [
    {
      "id": 63,
      "knowledgeBaseId": 7,
      "documentName": "131.3-Visa-Requirements-Schengen-2021-05 (1) (1).pdf",
      "chunk": "and for the whole period of staying in the Schengen area. In order to have a flexible travel schedule it is suggested to issue the Insurance for a few days longer than the planned travel time...",
      "distance": 0.7506968916261936
    },
    {
      "id": 76,
      "knowledgeBaseId": 7,
      "documentName": "131.3-Visa-Requirements-Schengen-2021-05 (1) (1).pdf",
      "chunk": "plan agreed with the clinic. Medical health documentation issued by the applicant’s country of residence...",
      "distance": 0.7515738980069386
    }
  ]
```

### Integration retrieval with Chat Setup

Combine semantic retrieval with chat models for powerful RAG applications:

```bash theme={null}
# 1. Search for relevant context
  curl --request POST \
  --url https://api.pawa-ai.com/v1/store/knowledge-base/semantic-retrieval \
  --header "Authorization: Bearer $PAWA_AI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "knowledge_base_id": "23",
  "question_asked_by_user": "When WCF got started?"
}'

# 2. Use retrieved context in chat
    curl https://api.pawa-ai.com/v1/chat/request \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $PAWA_AI_API_KEY" \
      -d '{
        "model": "pawa-v1-blaze-20250318",
    "messages": [
      {
        "role": "system",
        "content": [
          {
            "type": "text",
            "text": "Answer based on the provided context. If you cannot find the answer in the context, say so."
          }
        ]
      },
      {
        "role": "user", 
        "content": [
          {
            "type": "text",
            "text": "Context: [retrieved documents]\n\nQuestion: How do I request time off?"
          }
        ]
      }
    ]
  }'
```

### Best Practices

* **Use descriptive queries**: "What are the steps to file a complaint?" vs "complaint"
* **Optimize chunk size**: 500-1000 characters work well for most documents
* **Filter by metadata**: Use file types, dates, or categories to narrow results
* **Combine with keywords**: Use both semantic and keyword search for comprehensive results
* **Monitor relevance scores**: Adjust top\_k based on score thresholds

#### Multi-language Support

Query in English or Swahili - Pawa AI understands both:

```bash theme={null}
# English query
"Find information about employee benefits"

# Swahili query  
"Tafuta taarifa kuhusu faida za wafanyakazi"
```

### Troubleshooting

* **Low relevance scores**: Try rephrasing queries or checking document quality
* **Missing results**: Ensure documents are properly indexed and not corrupted
* **Slow responses**: Reduce top\_k or optimize document chunk sizes
* **Language mismatch**: Query in the same language as your documents for best results

### Limits

* Maximum query length: 1000 characters
* Maximum documents per knowledge base: depends on your plan
* Response time: typically under 2 seconds for most queries
