Vectorstore Manifest
Constants for Vectorstore manifest models.
Smarter API Manifest - Vectorstore.metadata
- class smarter.apps.vectorstore.manifest.models.vectorstore.metadata.SAMVectorstoreMetadata(*, name: str, description: str | None, version: str | None, tags: List[str] | None = <factory>, annotations: List[dict[str, str | int | float | bool | ~datetime.date | ~datetime.datetime | ~decimal.Decimal | ~uuid.UUID | bytes | list | dict]] | None=<factory>)[source]
Bases:
AbstractSAMMetadataBaseSmarter API Vectorstore Manifest - Metadata class.
Smarter API Manifest - Vectorstore.spec.
A Vectorstore is a vector database for retrieval-augmented generation (RAG): documents are split into chunks, embedded with a Provider’s embeddings model, and loaded into it, and searched by meaning. It is either self-hosted, by Smarter on its Kubernetes cluster, or a managed service reached through an ApiConnection.
spec:
backend: qdrant # qdrant or pinecone
hosting: self_hosted # self_hosted (qdrant only), or managed
connection: null # managed only: an ApiConnection with the service's URL and API key
isActive: true
index:
dimension: 1536 # must be the embeddings model's
metric: cosine # cosine, euclidean or dotproduct
deletionProtection: false
embeddings:
provider: openai # a Provider with an OpenAI-compatible embeddings API
model: text-embedding-3-small
chunkSize: 1000 # characters per chunk
chunkOverlap: 200
selfHosted: # self_hosted only
storage: 10Gi
cpu: 500m
memory: 1Gi
pinecone: # pinecone only
cloud: aws
region: us-east-1
maintenance:
snapshots: true # Qdrant snapshots, or Pinecone backups, taken by Celery Beat
snapshotIntervalHours: 24
snapshotRetention: 7
- class smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstoreEmbeddings(*, provider: Annotated[str, MinLen(min_length=1)], model: Annotated[str, MinLen(min_length=1)], dimensions: Annotated[int | None, Ge(ge=1), Le(le=20000)] = None, chunkSize: Annotated[int, Ge(ge=100), Le(le=8000)] = 1000, chunkOverlap: Annotated[int, Ge(ge=0), Le(le=2000)] = 200, batchSize: Annotated[int, Ge(ge=1), Le(le=1000)] = 64)[source]
Bases:
SmarterBasePydanticModelVectorstore.spec.embeddings: how documents and queries are turned into vectors.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- class smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstoreIndex(*, name: Annotated[str | None, MaxLen(max_length=45)] = None, dimension: Annotated[int, Ge(ge=1), Le(le=20000)], metric: Literal['cosine', 'euclidean', 'dotproduct'] = 'cosine', deletionProtection: bool = False)[source]
Bases:
SmarterBasePydanticModelVectorstore.spec.index: the index (Pinecone), or collection (Qdrant), of the database.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- class smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstoreMaintenance(*, snapshots: bool = True, snapshotIntervalHours: Annotated[int, Ge(ge=1), Le(le=720)] = 24, snapshotRetention: Annotated[int, Ge(ge=1), Le(le=100)] = 7)[source]
Bases:
SmarterBasePydanticModelVectorstore.spec.maintenance: what Celery Beat does, besides checking its status.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- class smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstorePinecone(*, cloud: Literal['aws', 'gcp', 'azure'] = 'aws', region: Annotated[str, MinLen(min_length=1)] = 'us-east-1')[source]
Bases:
SmarterBasePydanticModelVectorstore.spec.pinecone: where Pinecone runs a serverless index.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- class smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstoreSelfHosted(*, image: str = 'qdrant/qdrant:v1.19.1', storage: str = '10Gi', storageClass: str | None = None, cpu: str = '500m', memory: str = '1Gi')[source]
Bases:
SmarterBasePydanticModelVectorstore.spec.selfHosted: the Qdrant server that Smarter runs on Kubernetes.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- class smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstoreSpec(*, backend: ~typing.Literal['qdrant', 'pinecone'], hosting: ~typing.Literal['self_hosted', 'managed'] = 'managed', connection: str | None = None, isActive: bool = True, index: ~smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstoreIndex, embeddings: ~smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstoreEmbeddings, selfHosted: ~smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstoreSelfHosted | None = None, pinecone: ~smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstorePinecone | None = None, maintenance: ~smarter.apps.vectorstore.manifest.models.vectorstore.spec.SAMVectorstoreMaintenance = <factory>)[source]
Bases:
AbstractSAMSpecBaseSmarter API Vectorstore Manifest Vectorstore.spec.
- embeddings: SAMVectorstoreEmbeddings
- index: SAMVectorstoreIndex
- maintenance: SAMVectorstoreMaintenance
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- pinecone: SAMVectorstorePinecone | None
- selfHosted: SAMVectorstoreSelfHosted | None
Smarter API Manifest - Vectorstore.status.
- class smarter.apps.vectorstore.manifest.models.vectorstore.status.SAMVectorstoreStatus(*, recordLocator: str, created: datetime, modified: datetime, accountNumber: str, username: str, vectorstoreStatus: str, message: str | None = None, indexName: str | None = None, endpoint: str | None = None, apiKeySecret: str | None = None, vectorCount: int = 0, documentCount: int = 0, snapshotCount: int = 0, deployedAt: datetime | None = None, lastCheckedAt: datetime | None = None, lastSnapshotAt: datetime | None = None, lastMaintenanceAt: datetime | None = None)[source]
Bases:
AbstractSAMStatusBaseSmarter API Vectorstore Manifest - Status class.
Read only.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
Smarter API Vectorstore Manifest.
- class smarter.apps.vectorstore.manifest.models.vectorstore.model.SAMVectorstore(*, apiVersion: str, kind: str, metadata: SAMVectorstoreMetadata, spec: SAMVectorstoreSpec, status: SAMVectorstoreStatus | None = None)[source]
Bases:
AbstractSAMBaseSmarter API Manifest - Vectorstore.
- metadata: SAMVectorstoreMetadata
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- spec: SAMVectorstoreSpec
- status: SAMVectorstoreStatus | None
Smarter API Vectorstore Manifest handler.
The broker converts between Vectorstore manifests and the
VectorstoreMeta model, and implements the smarter
CLI commands for Vectorstores:
apply: create or update the Vectorstore. It does not create the database.deploy: create the database: a self-hosted Qdrant server, or a managed index.undeploy: stop serving. A self-hosted server’s data is kept.delete: destroy the database and all of its data, unless deletionProtection is enabled, then delete the Vectorstore.describe,get,logsandexample_manifest.
Account admins, i.e. staff, may apply, deploy, undeploy and delete their own Vectorstores. Anyone may describe and get the Vectorstores that are shared with them.
- class smarter.apps.vectorstore.manifest.brokers.vectorstore.SAMVectorstoreBroker(*args, **kwargs)[source]
Bases:
AbstractBrokerBroker for Vectorstore manifests.
See the module’s documentation.
- property ORMMetaModelClass: Type[VectorstoreMeta]
Return the Django ORM meta model class for the broker.
- Returns:
The Django ORM meta model class definition for the broker.
- Return type:
- property ORMModelClass: Type[VectorstoreMeta]
Return the Django ORM model class for the broker.
- Returns:
The Django ORM model class definition for the broker.
- Return type:
- property SerializerClass: Type[ModelSerializer]
Return the serializer class for the broker.
- Returns:
The serializer class definition for the broker.
- Return type:
Type[ModelSerializer]
- apply(request, *args, **kwargs)[source]
Create or update the Vectorstore.
It does not create its database: deploy does.
Once it is deployed, its backend, hosting, index, and self-hosted storage cannot change, because the database would no longer match. If its embeddings model changes, its loaded documents are loaded again.
- Return type:
- delete(request, *args, **kwargs)[source]
Destroy the database and its data, unless deletionProtection is enabled, then delete the Vectorstore.
- Return type:
- deploy(request, *args, **kwargs)[source]
Create the database.
A self-hosted server takes a minute or two to become ready: follow it with describe.
- Return type:
- describe(request, *args, **kwargs)[source]
The Vectorstore as a manifest, with its status.
- Return type:
- example_manifest(request, *args, **kwargs)[source]
An example Vectorstore manifest: a self-hosted Qdrant database for a knowledge base.
- Return type:
- property formatted_class_name: str
Return the logger prefix for the AbstractBroker.
- Returns:
The logger prefix for the AbstractBroker.
- Return type:
- get(request, *args, **kwargs)[source]
The Vectorstores that the user may read, optionally filtered by name.
- Return type:
- property manifest: SAMVectorstore | None
The Vectorstore manifest, as a Pydantic model, from the manifest loader.
- property orm_instance: VectorstoreMeta | None
Return the Django ORM model instance for the broker.
There are multiple strategies to retrieve the ORM instance:
If the instance is already cached in self._orm_instance, return it.
If the broker is not ready or the name is not set, log a warning and return None.
Attempt to retrieve the ORM instance using the user_profile and name. If not found, attempt to retrieve using the admin user_profile for the account. If still not found, attempt to retrieve using the Smarter platform admin user_profile.
Cache the retrieved instance for future access.
- Returns:
The Django ORM model instance for the broker.
- Return type:
Optional[MetaDataWithOwnershipModel]
- property orm_meta_instance: VectorstoreMeta | None
Return the Django ORM meta model instance for the broker.
This is a cached property that retrieves the ORM meta instance based on the user_profile and kind. For simple relational models, the ORM meta class is the same as the ORM class, and the meta instance is the same as the ORM instance.
This property is used for resolving more complex ORM relationships where the name and user_profile fields are stored in a parent Django model.
- prompt(request, *args, **kwargs)[source]
Invoke a prompt operation.
This abstract method should be implemented by subclasses to provide prompt-based interactions with the broker resource.
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the prompt response.
- Return type:
- static reload_documents(vectorstore)[source]
Load the loaded documents again, e.g. with a new embeddings model.
- Return type:
- resolve_connection(name)[source]
Spec.connection: the user’s own ApiConnection, else one shared with them.
- Return type:
Optional[ApiConnection]
- resolve_provider(name)[source]
Spec.embeddings.provider: the user’s own Provider, else the most recently updated one shared with them.
- Return type:
- undeploy(request, *args, **kwargs)[source]
Stop serving.
A self-hosted server’s data is kept, and a managed index is left as it is.
- Return type:
- property vectorstore: VectorstoreMeta | None
The user’s own Vectorstore with the broker’s name, else one shared with them.
It is never created here.