REST API

Vectorstore api/v1/vectorstores views.

Vectorstores are created and updated by applying manifests, with smarter apply. These views load and search them, and maintain them:

  • GET vectorstores/: the vectorstores that the user may read.

  • GET vectorstores/<hashed_id>/: a vectorstore that the user may read.

  • GET vectorstores/<hashed_id>/status/: check its status and statistics, now.

  • POST vectorstores/<hashed_id>/deploy/ and POST vectorstores/<hashed_id>/undeploy/.

  • GET vectorstores/<hashed_id>/documents/: its documents.

  • POST vectorstores/<hashed_id>/documents/: add documents, and queue them to be loaded: files, as multipart/form-data, or JSON {"name": ..., "text": ...} or {"url": ...}.

  • DELETE vectorstores/<hashed_id>/documents/<document_id>/: remove a document, and its chunks.

  • POST vectorstores/<hashed_id>/search/: {"query": ..., "k": 4, "searchType": "similarity", "scoreThreshold": null, "fetchK": null, "lambdaMult": null, "filter": {}}.

  • GET vectorstores/<hashed_id>/snapshots/: its snapshots, or backups.

  • POST vectorstores/<hashed_id>/snapshots/: take one now.

  • POST vectorstores/<hashed_id>/snapshots/<snapshot_id>/restore/: restore one.

Reading and searching require read permission. Everything else requires ownership.

class smarter.apps.vectorstore.api.v1.views.VectorstoreDeployView(*args, **kwargs)[source]

Bases: VectorstoreViewBase

Create the database of a vectorstore that the user owns.

post(request, *args, **kwargs)[source]
class smarter.apps.vectorstore.api.v1.views.VectorstoreDocumentView(*args, **kwargs)[source]

Bases: VectorstoreViewBase

Remove a document, and its chunks, from a vectorstore that the user owns.

delete(request, *args, **kwargs)[source]
class smarter.apps.vectorstore.api.v1.views.VectorstoreDocumentsView(*args, **kwargs)[source]

Bases: VectorstoreViewBase

List a vectorstore’s documents, or add documents to one that the user owns.

get(request, *args, **kwargs)[source]
post(request, *args, **kwargs)[source]

Add documents, and queue them to be loaded.

Files, as multipart/form-data, are read, and their text extracted, now. The files themselves are not kept. Optional metadata, a JSON object, is stored with each chunk.

static sources(request)[source]

The documents of a request: uploaded files, text, or a URL.

class smarter.apps.vectorstore.api.v1.views.VectorstoreListView(*args, **kwargs)[source]

Bases: SmarterAuthenticatedListAPIView

The vectorstores that the user may read.

get_queryset(*args, **kwargs)[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

Return type:

QuerySet

serializer_class

alias of VectorstoreSerializer

class smarter.apps.vectorstore.api.v1.views.VectorstoreRestoreView(*args, **kwargs)[source]

Bases: VectorstoreViewBase

Replace a vectorstore’s data with one of its snapshots.

post(request, *args, **kwargs)[source]
class smarter.apps.vectorstore.api.v1.views.VectorstoreSearchView(*args, **kwargs)[source]

Bases: VectorstoreViewBase

Search a vectorstore that the user may read.

post(request, *args, **kwargs)[source]
class smarter.apps.vectorstore.api.v1.views.VectorstoreSnapshotsView(*args, **kwargs)[source]

Bases: VectorstoreViewBase

List a vectorstore’s snapshots, or take one now.

get(request, *args, **kwargs)[source]
post(request, *args, **kwargs)[source]
class smarter.apps.vectorstore.api.v1.views.VectorstoreStatusView(*args, **kwargs)[source]

Bases: VectorstoreViewBase

Check a vectorstore’s status and statistics, now.

get(request, *args, **kwargs)[source]
class smarter.apps.vectorstore.api.v1.views.VectorstoreUndeployView(*args, **kwargs)[source]

Bases: VectorstoreViewBase

Stop serving a vectorstore that the user owns.

A self-hosted server’s data is kept.

post(request, *args, **kwargs)[source]
class smarter.apps.vectorstore.api.v1.views.VectorstoreView(*args, **kwargs)[source]

Bases: VectorstoreViewBase

A vectorstore that the user may read.

get(request, *args, **kwargs)[source]
serializer_class

alias of VectorstoreSerializer

class smarter.apps.vectorstore.api.v1.views.VectorstoreViewBase(*args, **kwargs)[source]

Bases: SmarterAuthenticatedAPIView

Base class of the views of one vectorstore, identified by hashed_id or vectorstore_id.

get_vectorstore() returns it only if the user may read it, or, with owner=True, owns it. Otherwise it raises Http404, so that other accounts’ vectorstores are not disclosed.

get_service(vectorstore)[source]
Return type:

VectorstoreService

get_vectorstore(request, owner=False, **kwargs)[source]
Return type:

VectorstoreMeta

service_class

alias of VectorstoreService

smarter.apps.vectorstore.api.v1.views.error(message, status=HTTPStatus.BAD_REQUEST)[source]
Return type:

JsonResponse

URL configuration for the Vectorstore app API.

These are mounted at /api/v1/vectorstores/. See smarter.apps.vectorstore.api.v1.views.

smarter.apps.vectorstore.api.v1.urls.PER_VECTORSTORE = {'': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreView'>, 'deploy/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreDeployView'>, 'documents/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreDocumentsView'>, 'documents/<int:document_id>/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreDocumentView'>, 'search/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreSearchView'>, 'snapshots/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreSnapshotsView'>, 'snapshots/<int:snapshot_id>/restore/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreRestoreView'>, 'status/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreStatusView'>, 'undeploy/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreUndeployView'>}

The views of one vectorstore, by URL suffix.

{
    '': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreView'>,
    'deploy/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreDeployView'>,
    'documents/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreDocumentsView'>,
    'documents/<int:document_id>/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreDocumentView'>,
    'search/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreSearchView'>,
    'snapshots/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreSnapshotsView'>,
    'snapshots/<int:snapshot_id>/restore/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreRestoreView'>,
    'status/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreStatusView'>,
    'undeploy/': <class 'smarter.apps.vectorstore.api.v1.views.VectorstoreUndeployView'>,
}
class smarter.apps.vectorstore.api.v1.urls.VectorstoreApiV1ReverseViews[source]

Bases: object

Reverse view names of the Vectorstore api.

Each is available by the vectorstore’s hashed id, and by its id.

url = reverse(
    f"{VectorstoreApiV1ReverseViews.namespace}:{VectorstoreApiV1ReverseViews.search_by_hashed_id}",
    kwargs={"hashed_id": vectorstore.hashed_id},
)
deploy_by_hashed_id = 'vectorstore_deploy_view_by_hashed_id'
document_by_hashed_id = 'vectorstore_document_view_by_hashed_id'
documents_by_hashed_id = 'vectorstore_documents_view_by_hashed_id'
list_view = 'vectorstore_list_view'
namespace = 'api:v1:vectorstore'
restore_by_hashed_id = 'vectorstore_restore_view_by_hashed_id'
search_by_hashed_id = 'vectorstore_search_view_by_hashed_id'
snapshots_by_hashed_id = 'vectorstore_snapshots_view_by_hashed_id'
status_by_hashed_id = 'vectorstore_status_view_by_hashed_id'
undeploy_by_hashed_id = 'vectorstore_undeploy_view_by_hashed_id'
vectorstore_by_hashed_id = 'vectorstore_view_by_hashed_id'