> For the complete documentation index, see [llms.txt](https://docs.hyper-space.io/hyperspace-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hyper-space.io/hyperspace-docs/~/changes/uCQNjcW7J3OXknfYJaVa/api-documentation/score-function/rarity_sum.md).

# rarity\_sum

`rarity_sum(str fieldname)`calculates the rarity score for matched keywords. The function calculates the score over keywords or lists of keywords, using the TF-IDF formula.&#x20;

### Input

* <mark style="color:purple;">fieldname1</mark> (str) - the name of the field to match in query document. params\[fieldname1] must be of type **keyword** or **list\[keyword]**
* <mark style="color:purple;">fieldname2</mark> (str, default=fieldname1) - the name of the field to match in database document. V\[fieldname2] must be of type **keyword** or **list\[keyword]**

### Output

* <mark style="color:purple;">(float)</mark> - TF-IDF for the matched keywords. If params\[fieldname] and params\[fieldname] are lists of, the function will return the **sum of rarity score out of** all matched keywords

**Example:**

```python
Score = rarity_sum("cities")
```

The function will return the sum of rarity scores of all matched keywords between params\["cities"] and V\["cities"]


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hyper-space.io/hyperspace-docs/~/changes/uCQNjcW7J3OXknfYJaVa/api-documentation/score-function/rarity_sum.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
