for progress, msg in doc.join(interval=5, timeout=30):
print(progress, msg)
for c in rag.retrieval(question="What's ragflow?",
datasets=[ds], documents=[doc],
offset=0, limit=6, similarity_threshold=0.1,
vector_similarity_weight=0.3,
top_k=1024
):
print(c)
```
---
:::tip API GROUPING
Chat assistant APIs
:::
## Create assistant
```python
RAGFlow.create_assistant(
name: str = "assistant",
avatar: str = "path",
knowledgebases: List[DataSet] = ["kb1"],
llm: Assistant.LLM = None,
prompt: Assistant.Prompt = None
) -> Assistant
```
### Returns
Assistant object.
#### name: `str`
The name of the created assistant. Defaults to `"assistant"`.
#### avatar: `str`
The icon of the created assistant. Defaults to `"path"`.
#### knowledgebases: `List[DataSet]`
Select knowledgebases associated. Defaults to `["kb1"]`.
#### id: `str`
The id of the created assistant. Defaults to `""`.
#### llm: `LLM`
The llm of the created assistant. Defaults to `None`. When the value is `None`, a dictionary with the following values will be generated as the default.
- **model_name**, `str`
Large language chat model. If it is `None`, it will return the user's default model.
- **temperature**, `float`
This parameter controls the randomness of predictions by the model. A lower temperature makes the model more confident in its responses, while a higher temperature makes it more creative and diverse. Defaults to `0.1`.
- **top_p**, `float`
Also known as “nucleus sampling,” this parameter sets a threshold to select a smaller set of words to sample from. It focuses on the most likely words, cutting off the less probable ones. Defaults to `0.3`
- **presence_penalty**, `float`
This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
- **frequency penalty**, `float`
Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
- **max_token**, `int`
This sets the maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
#### Prompt: `str`
Instructions you need LLM to follow when LLM answers questions, like character design, answer length and answer language etc.
Defaults:
```
You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence "The answer you are looking for is not found in the knowledge base!" Answers need to consider chat history.
ID of the assistant to retrieve. If `name` is not provided, `id` is required.
#### name: `str`
Name of the assistant to retrieve. If `id` is not provided, `name` is required.
### Returns
Assistant object.
#### name: `str`
The name of the created assistant. Defaults to `"assistant"`.
#### avatar: `str`
The icon of the created assistant. Defaults to `"path"`.
#### knowledgebases: `List[DataSet]`
Select knowledgebases associated. Defaults to `["kb1"]`.
#### id: `str`
The id of the created assistant. Defaults to `""`.
#### llm: `LLM`
The llm of the created assistant. Defaults to `None`. When the value is `None`, a dictionary with the following values will be generated as the default.
- **model_name**, `str`
Large language chat model. If it is `None`, it will return the user's default model.
- **temperature**, `float`
This parameter controls the randomness of predictions by the model. A lower temperature makes the model more confident in its responses, while a higher temperature makes it more creative and diverse. Defaults to `0.1`.
- **top_p**, `float`
Also known as “nucleus sampling,” this parameter sets a threshold to select a smaller set of words to sample from. It focuses on the most likely words, cutting off the less probable ones. Defaults to `0.3`
- **presence_penalty**, `float`
This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
- **frequency penalty**, `float`
Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
- **max_token**, `int`
This sets the maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
#### Prompt: `str`
Instructions you need LLM to follow when LLM answers questions, like character design, answer length and answer language etc.
Defaults:
```
You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence "The answer you are looking for is not found in the knowledge base!" Answers need to consider chat history.
The question to start an AI chat. Defaults to `None`. ???????????????????
#### stream: `bool`
The approach of streaming text generation. When stream is True, it outputs results in a streaming fashion; otherwise, it outputs the complete result after the model has finished generating.
#### session_id: `str` ??????????????????
### Returns
[Message, iter[Message]]
#### id: `str`
The id of the message. `id` is automatically generated. Defaults to `None`. ???????????????????
#### content: `str`
The content of the message. Defaults to `"Hi! I am your assistant, can I help you?"`.
#### reference: `List[Chunk]`
The auto-generated reference of the message. Each `chunk` object includes the following attributes:
- **id**: `str`
The id of the chunk. ?????????????????
- **content**: `str`
The content of the chunk. Defaults to `None`. ?????????????????????
- **document_id**: `str`
The ID of the document being referenced. Defaults to `""`.
- **document_name**: `str`
The name of the referenced document being referenced. Defaults to `""`.
- **knowledgebase_id**: `str`
The id of the knowledge base to which the relevant document belongs. Defaults to `""`.
- **image_id**: `str`
The id of the image related to the chunk. Defaults to `""`.
- **similarity**: `float`
A general similarity score, usually a composite score derived from various similarity measures . This score represents the degree of similarity between two objects. The value ranges between 0 and 1, where a value closer to 1 indicates higher similarity. Defaults to `None`. ????????????????????????????????????
- **vector_similarity**: `float`
A similarity score based on vector representations. This score is obtained by converting texts, words, or objects into vectors and then calculating the cosine similarity or other distance measures between these vectors to determine the similarity in vector space. A higher value indicates greater similarity in the vector space. Defaults to `None`. ?????????????????????????????????
- **term_similarity**: `float`
The similarity score based on terms or keywords. This score is calculated by comparing the similarity of key terms between texts or datasets, typically measuring how similar two words or phrases are in meaning or context. A higher value indicates a stronger similarity between terms. Defaults to `None`. ???????????????????
- **position**: `List[string]`
Indicates the position or index of keywords or specific terms within the text. An array is typically used to mark the location of keywords or specific elements, facilitating precise operations or analysis of the text. Defaults to `None`. ??????????????