Skip to content

Latest commit

 

History

History
841 lines (559 loc) · 87 KB

File metadata and controls

841 lines (559 loc) · 87 KB

Knowledge

Overview

Available Operations

list

Returns a list of your knowledge bases. The knowledge bases are returned sorted by creation date, with the most recent knowledge bases appearing first

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.list(limit=10)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
limit Optional[int] A limit on the number of objects to be returned. Limit can range between 1 and 50, and the default is 10
starting_after Optional[str] A cursor for use in pagination. starting_after is an object ID that defines your place in the list. For instance, if you make a list request and receive 20 objects, ending with 01JJ1HDHN79XAS7A01WB3HYSDB, your subsequent call can include after=01JJ1HDHN79XAS7A01WB3HYSDB in order to fetch the next page of the list.
ending_before Optional[str] A cursor for use in pagination. ending_before is an object ID that defines your place in the list. For instance, if you make a list request and receive 20 objects, starting with 01JJ1HDHN79XAS7A01WB3HYSDB, your subsequent call can include before=01JJ1HDHN79XAS7A01WB3HYSDB in order to fetch the previous page of the list.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ListKnowledgeBasesResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

create

Create a knowledge

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.create(request={
        "type": "internal",
        "key": "<key>",
        "embedding_model": "<value>",
        "path": "Default",
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
request models.CreateKnowledgeRequestBody ✔️ The request object to use for the request.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.CreateKnowledgeResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

retrieve

Retrieve a knowledge base with the settings.

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.retrieve(knowledge_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ Unique identifier of the knowledge base
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.GetOneKnowledgeResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

update

Updates a knowledge

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.update(knowledge_id="<id>", request_body={
        "path": "Default",
        "type": "external",
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
request_body models.UpdateKnowledgeRequestBody ✔️ N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.UpdateKnowledgeResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

delete

Deletes a knowledge base. Deleting a knowledge base will delete all the datasources and chunks associated with it.

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    orq.knowledge.delete(knowledge_id="<id>")

    # Use the SDK ...

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

search

Search a Knowledge Base and return the most similar chunks, along with their search and rerank scores. Note that all configuration changes made in the API will override the settings in the UI.

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.search(knowledge_id="<id>", query="<value>", search_type="hybrid_search", rerank_config={
        "model": "cohere/rerank-multilingual-v3.0",
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier or key of the knowledge base
query str ✔️ The query to use to search the knowledge base
top_k Optional[int] The number of results to return. If not provided, will default to the knowledge base configured top_k.
threshold Optional[float] The threshold to apply to the search. If not provided, will default to the knowledge base configured threshold
search_type Optional[models.SearchType] The type of search to perform. If not provided, will default to the knowledge base configured retrieval_type
filter_by Optional[models.FilterBy] The metadata filter to apply to the search. Check the Searching a Knowledge Base for more information.
search_options Optional[models.SearchOptions] Additional search options
rerank_config Optional[models.RerankConfig] Override the rerank configuration for this search. If not provided, will use the knowledge base configured rerank settings.
agentic_rag_config Optional[models.AgenticRagConfig] Override the agentic RAG configuration for this search. If not provided, will use the knowledge base configured agentic RAG settings.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.SearchKnowledgeResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

list_datasources

List all datasources

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.list_datasources(knowledge_id="<id>", limit=50, status=[
        "completed",
        "failed",
    ])

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ Unique identifier of the knowledge base
starting_after Optional[str] A cursor for use in pagination. starting_after is an object ID that defines your place in the list. For instance, if you make a list request and receive 20 objects, ending with 01JJ1HDHN79XAS7A01WB3HYSDB, your subsequent call can include after=01JJ1HDHN79XAS7A01WB3HYSDB in order to fetch the next page of the list.
ending_before Optional[str] A cursor for use in pagination. ending_before is an object ID that defines your place in the list. For instance, if you make a list request and receive 20 objects, starting with 01JJ1HDHN79XAS7A01WB3HYSDB, your subsequent call can include before=01JJ1HDHN79XAS7A01WB3HYSDB in order to fetch the previous page of the list.
q Optional[str] Search query to find datasources by name.
limit Optional[float] A limit on the number of objects to be returned. Limit can range between 1 and 50, and the default is 10
status Optional[models.QueryParamStatus] Filter datasources by status.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ListDatasourcesResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

create_datasource

Create a new datasource

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.create_datasource(knowledge_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
display_name Optional[str] The display name for the datasource visible in the UI. If omitted, the display name is derived from the uploaded file. When both display_name and file_id are provided, the provided display_name is prioritized.
file_id Optional[str] The unique identifier of the file used for datasource creation. If provided, the file is immediately queued for chunking.
chunking_options Optional[models.ChunkingOptions] Configuration options specifying how the datasource file is chunked. Required if file_id is specified. Defaults to standard chunking options if omitted.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.CreateDatasourceResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

retrieve_datasource

Retrieve a datasource

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.retrieve_datasource(knowledge_id="<id>", datasource_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
datasource_id str ✔️ The unique identifier of the datasource.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.RetrieveDatasourceResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

delete_datasource

Deletes a datasource from a knowledge base. Deleting a datasource will remove it from the knowledge base and all associated chunks. This action is irreversible and cannot be undone.

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    orq.knowledge.delete_datasource(knowledge_id="<id>", datasource_id="<id>")

    # Use the SDK ...

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
datasource_id str ✔️ The unique identifier of the datasource.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

update_datasource

Update a datasource

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.update_datasource(knowledge_id="<id>", datasource_id="<id>", display_name="Tony_Roberts")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
datasource_id str ✔️ The unique identifier of the datasource.
display_name str ✔️ N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.UpdateDatasourceResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

create_chunks

Create chunks for a datasource

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.create_chunks(knowledge_id="<id>", datasource_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ Unique identifier of the knowledge
datasource_id str ✔️ Unique identifier of the datasource
request_body List[models.RequestBody] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

List[models.CreateChunkResponseBody]

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

list_chunks

List all chunks for a datasource

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.list_chunks(knowledge_id="<id>", datasource_id="<id>", limit=10, status=[
        "completed",
        "failed",
    ])

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
datasource_id str ✔️ The unique identifier of the datasource.
limit Optional[int] A limit on the number of objects to be returned. Limit can range between 1 and 50, and the default is 10
starting_after Optional[str] A cursor for use in pagination. starting_after is an object ID that defines your place in the list. For instance, if you make a list request and receive 20 objects, ending with 01JJ1HDHN79XAS7A01WB3HYSDB, your subsequent call can include after=01JJ1HDHN79XAS7A01WB3HYSDB in order to fetch the next page of the list.
ending_before Optional[str] A cursor for use in pagination. ending_before is an object ID that defines your place in the list. For instance, if you make a list request and receive 20 objects, starting with 01JJ1HDHN79XAS7A01WB3HYSDB, your subsequent call can include before=01JJ1HDHN79XAS7A01WB3HYSDB in order to fetch the previous page of the list.
q Optional[str] Search query to find datasources by name.
status Optional[models.ListChunksQueryParamStatus] Filter datasources by status.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ListChunksResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

delete_chunks

Delete multiple chunks

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.delete_chunks(knowledge_id="<id>", datasource_id="<id>", chunk_ids=[
        "<value 1>",
        "<value 2>",
    ])

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
datasource_id str ✔️ The unique identifier of the datasource.
chunk_ids List[str] ✔️ Array of chunk IDs to delete
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.DeleteChunksResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

list_chunks_paginated

List chunks with offset-based pagination

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.list_chunks_paginated(knowledge_id="<id>", datasource_id="<id>", q="", limit=100, page=1)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
datasource_id str ✔️ The unique identifier of the datasource.
q Optional[str] Search query to find chunks by text content
enabled Optional[bool] Filter chunks by enabled status
status Optional[str] Filter chunks by processing status
limit Optional[int] N/A
page Optional[int] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ListChunksPaginatedResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

get_chunks_count

Get chunks total count

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.get_chunks_count(knowledge_id="<id>", datasource_id="<id>", q="")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
knowledge_id str ✔️ The unique identifier of the knowledge base
datasource_id str ✔️ The unique identifier of the datasource.
q Optional[str] Search query to find chunks by text content
enabled Optional[bool] Filter chunks by enabled status
status Optional[str] Filter chunks by processing status
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.GetChunksCountResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

update_chunk

Update a chunk

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.update_chunk(chunk_id="<id>", datasource_id="<id>", knowledge_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
chunk_id str ✔️ The unique identifier of the chunk
datasource_id str ✔️ The unique identifier of the data source
knowledge_id str ✔️ The unique identifier of the knowledge base
text Optional[str] The text content of the chunk
embedding List[float] The embedding vector of the chunk. If not provided the chunk will be embedded with the knowledge base embeddings model.
metadata Dict[str, models.UpdateChunkMetadata] Metadata of the chunk
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.UpdateChunkResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

delete_chunk

Delete a chunk

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    orq.knowledge.delete_chunk(chunk_id="<id>", datasource_id="<id>", knowledge_id="<id>")

    # Use the SDK ...

Parameters

Parameter Type Required Description
chunk_id str ✔️ The unique identifier of the chunk
datasource_id str ✔️ The unique identifier of the data source
knowledge_id str ✔️ The unique identifier of the knowledge base
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*

retrieve_chunk

Retrieve a chunk

Example Usage

from orq_ai_sdk import Orq
import os


with Orq(
    api_key=os.getenv("ORQ_API_KEY", ""),
) as orq:

    res = orq.knowledge.retrieve_chunk(chunk_id="<id>", datasource_id="<id>", knowledge_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
chunk_id str ✔️ The unique identifier of the chunk
datasource_id str ✔️ The unique identifier of the data source
knowledge_id str ✔️ The unique identifier of the knowledge base
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.GetOneChunkResponseBody

Errors

Error Type Status Code Content Type
models.APIError 4XX, 5XX */*