localvectordb.visualization.dimensionality module

Dimensionality reduction utilities (PCA, t-SNE).

localvectordb.visualization._dimensionality.reduce_dimensions(embeddings: ndarray, method: str = 'tsne', n_components: int = 2, doc_ids: List[str] | None = None, **kwargs) EmbeddingProjection

Project high-dimensional embeddings into a lower-dimensional space.

Parameters:
  • embeddings (np.ndarray) – (N, D) array of embeddings.

  • method (str) – "pca" or "tsne".

  • n_components (int) – Number of output dimensions (2 or 3).

  • doc_ids (list of str, optional) – Document IDs matching rows. Defaults to string indices.

  • **kwargs – Forwarded to the underlying sklearn estimator.

Return type:

EmbeddingProjection

localvectordb.visualization._dimensionality.project_new_points(projection: EmbeddingProjection, new_embeddings: ndarray) ndarray

Project new points into an existing reduced space.

For PCA this uses the fitted transform directly. For t-SNE the stored PCA fallback is used (t-SNE cannot transform unseen data).

Parameters:
  • projection (EmbeddingProjection) – Previously fitted projection.

  • new_embeddings (np.ndarray) – (M, D) new embeddings to project.

Returns:

(M, n_components) projected coordinates.

Return type:

np.ndarray