Skip to main content

Insights

This page is for the practitioner who wants analyst-facing insight sheets, the notes and visualizations attached to a document. All snippets below assume svi is an authenticated SVIClient.

An insight sheet is a NOTESHEET that lives on a document. It holds an ordered list of cells: text, image, table, summary, map, timeline, network, and text-analytics. There is no sasvi.insights client namespace. Every sheet hangs off a bound document, so you reach it through document.insights, and you import the cell factories from the sasvi.insights package.

Before this example​

Insight content depends on your entity types and their fields. Before you adapt a snippet, use Discover your environment to find:

  • a real entity type name and document id for "<your-entity-type>" / "<your-document-id>"
  • the real field names behind placeholders like "<your-score-field>"

Assume the examples below start from a bound document:

document = svi.documents.get(
entity_type_name="<your-entity-type>",
document_id="<your-document-id>",
)

Create an insight sheet​

Create a sheet with an optional list of initial cells. InsightCell is the factory for typed cell payloads:

from sasvi.insights import InsightCell

if document is not None:
insight = document.insights.create(
name="Analyst Notes",
cells=[InsightCell.text("<p>Opened for review</p>", width=6)],
)
print(insight.id, insight.name)

document.insights.create(...) returns an InsightHandle. A sheet is never created empty: create(name=...) without cells, or with cells=[], seeds one text cell reading "Insight created via API on <timestamp>.", because the server may reject a sheet with no cells. Add your own cells afterwards and remove the placeholder with insight.cells.remove(cell_id=...) if you do not want it.

Add cells​

The sheet's cells manager adds cells one at a time and materializes each against the server. The grid is laid out by row, position, width, and height.

Text and image​

if document is not None:
insight = document.insights.create(name="Review Sheet")
insight.cells.add_text(contents="<p>First note</p>", width=6)
insight.cells.add_image(contents="/path/to/existing/image.png", width=5)

add_image(...) materializes the source immediately. Pass a local path, bytes, a file-like object, an HTTP/data URL, or an already-uploaded document image path.

Table, summary, timeline, and network from documents​

The *_from_documents helpers build a visualization cell directly from bound documents so you do not have to hand-write the VI filter payload:

if document is not None:
insight = document.insights.create(name="Case Summary")
insight.cells.add_table_from_documents(
documents=[document],
columns=["_label", "<your-score-field>", ("<your-related-field>", "Related field")],
width=6,
)
insight.cells.add_summary_from_documents(
documents=[document],
fields=["<your-score-field>", ("<your-related-field>", "Related field")],
width=6,
)
insight.cells.add_timeline_from_documents(
documents=[document],
events=["<your-created-timestamp-field>", ("<your-updated-timestamp-field>", "Updated")],
width=8,
)
insight.cells.add_network_from_documents(
documents=[
{
"type": document.document_type,
"id": document.document_id,
"displayLabel": document.label,
}
],
links=[],
width=8,
)

Map​

Map cells take explicit coordinate fields:

if document is not None:
insight = document.insights.create(name="Geo Sheet")
insight.cells.add_map_from_documents(
documents=[
{
"type": "<your-location-entity-type>",
"id": "<your-location-document-id>",
"displayLabel": "Location",
"fieldValues": {"latitude": 35.8024, "longitude": -78.6522},
}
],
latitude_field="latitude",
longitude_field="longitude",
zoom=18,
)

Read, reorder, and remove cells​

List cells back; each one is typed automatically so you can branch on the cell class:

from sasvi.documents import TableInsightCellHandle, TimelineInsightCellHandle

if document is not None:
insight = document.insights.get(insight_id=123)
if insight is not None:
for cell in insight.cells.list():
if isinstance(cell, TableInsightCellHandle):
print(cell.table_result)
elif isinstance(cell, TimelineInsightCellHandle):
print(cell.timeline_view_range)

Move or delete a single cell without rewriting the whole sheet:

if document is not None:
insight = document.insights.create(name="Triage Notes") # holds the placeholder cell
first = insight.cells.add_text(contents="<p>First</p>")
second = insight.cells.add_text(contents="<p>Second</p>")
moved = insight.cells.move(cell_id=second.id, position=0)
insight.cells.remove(cell_id=first.id)
print(moved.row, moved.position)

cells.move(...) changes the order the sheet renders: the cells keep the row and position slots the sheet already has and fill them in the new order.

Edits from a handle you have held for a while​

Every handle edit is applied to the sheet as it is when the SDK holds the document lock, not to the copy the handle holds. insight.update(name=...) writes only the keys you name. cells.add_* appends below the cells that exist at that moment. cells.update(...) writes only the cell keys you changed. cells.move(...) reorders the current cells. A cell a colleague added or edited in the meantime is kept.

An edit of a cell that a colleague has deleted raises DocumentOperationError naming the cell, and nothing is written. Call insight.refresh() and decide again.

The service-level document.insights.update(insight_id=..., insight=InsightUpdate(...)) follows the same rule for the top-level fields: name, uxState and tabOrder are merged onto the sheet as it is under the lock. cells, when given, replaces the whole cell list. To change single cells, use the handle's cells manager.

Render a sheet​

An InsightHandle renders to plain text or Markdown, which is handy for exports and LLM prompts:

if document is not None:
insight = document.insights.get(insight_id=123)
if insight is not None:
print(insight.to_text())
print(insight.to_markdown(include_cell_headings=True))

Async​

Insights are a partly sync-only surface. The sheet-level operations have real _async twins:

async def list_sheets(document):
sheets = await document.insights.list_async()
return [s.id for s in sheets]


async def get_sheet(document, insight_id):
return await document.insights.get_async(insight_id=insight_id)

The insight-cell managers are sync-only. insight.cells.add_text(...), add_table_from_documents(...), move(...), remove(...), and the other cells.* mutators have no _async twin. They orchestrate multi-step document-runtime patches, so there is no single async operation to await. From an async context, run them in a thread executor:

import asyncio

await asyncio.to_thread(insight.cells.add_text, contents="<p>From a worker thread</p>")

See the async guide's "sync-only surfaces" section for the full list. The sheet-level calls (document.insights.list_async, get_async, create_async, update_async and delete_async) are natively async.

Build cells without a sheet​

When you want a raw cell payload, for a bulk create or to validate a shape offline, use the InsightCell factory classmethods directly. They return typed models. The *_from_documents builders read the entity type once per distinct document type when you pass bound Document handles (one synchronous GET each, to resolve field labels and types); mapping payloads cause no I/O. From an async context, build such a cell inside the same asyncio.to_thread call as the cells.add_* that stores it:

from sasvi.insights import InsightCell

cells = [
InsightCell.text("<p>Standalone note</p>", width=6),
InsightCell.summary_from_documents(
documents=[document], fields=["<your-score-field>"], width=6
),
]

Unlike insight.cells.add_image(...), InsightCell.image(...) builds the raw payload without materializing the source. Use the bound cells.add_image(...) when you want the upload handled.

Errors​

  • Insight reads and writes raise DocumentOperationError when Data Hub rejects the request, and DocumentConflictError (an HTTP 412) when the document changed while the SDK held the lock. An edit of a cell a colleague deleted raises DocumentOperationError naming the cell.
  • The InsightCell.*_from_documents builders raise InsightInputError for input they cannot use: a document that is neither a bound handle nor a mapping, a shorthand tuple of the wrong length, a link endpoint that matches no document, or result= next to documents=. It is a ValueError as well. sasvi.insights.InsightsError is its base; no other insight path raises it.
  • document.insights.get(insight_id=...) returns None when the sheet id does not exist.

Go further​