> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Document Interfaces

> DocumentMetadata and DocumentEmbedding types

Interfaces for documents in VectoriaDB.

## DocumentMetadata

Base interface for document metadata. Your custom metadata must extend this.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
interface DocumentMetadata {
  /**
   * Unique identifier for the document
   */
  id: string;

  /**
   * Additional metadata fields (flexible)
   */
  [key: string]: any;
}
```

### Example

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
interface ToolDocument extends DocumentMetadata {
  toolName: string;
  owner: string;
  tags: string[];
  risk: 'safe' | 'destructive';
  deprecated?: boolean;
}

const db = new VectoriaDB<ToolDocument>();
```

***

## DocumentEmbedding

Stored document with embedding vector.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
interface DocumentEmbedding<T extends DocumentMetadata = DocumentMetadata> {
  /**
   * Unique identifier
   */
  id: string;

  /**
   * Vector representation (384 dimensions by default)
   */
  vector: Float32Array;

  /**
   * Associated metadata
   */
  metadata: T;

  /**
   * Original text used for embedding
   */
  text: string;

  /**
   * Timestamp when created
   */
  createdAt: Date;
}
```

### Example

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
const doc = db.get('users:list');

if (doc) {
  console.log(doc.id);          // 'users:list'
  console.log(doc.text);        // 'List all users...'
  console.log(doc.metadata);    // { id: 'users:list', toolName: 'list', ... }
  console.log(doc.createdAt);   // Date object
  console.log(doc.vector);      // Float32Array(384)
}
```

***

## DocumentData

Input format for document embedding generation.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
interface DocumentData {
  /**
   * Main text content
   */
  text: string;

  /**
   * Additional metadata (optional)
   */
  metadata?: Record<string, any>;
}
```

## Type Safety

VectoriaDB uses TypeScript generics for type-safe metadata:

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
interface MyDocument extends DocumentMetadata {
  title: string;
  category: string;
}

const db = new VectoriaDB<MyDocument>();

// TypeScript enforces metadata shape
await db.add('id', 'text', {
  id: 'id',
  title: 'My Title',
  category: 'docs',
  // TypeScript error if you add wrong fields
});

// Search results have typed metadata
const results = await db.search('query');
results[0].metadata.title; // string
results[0].metadata.category; // string
```

## Related

<CardGroup cols={3}>
  <Card title="Configuration" icon="gear" href="/vectoriadb/api-reference/interfaces/config">
    Config interfaces
  </Card>

  <Card title="Search" icon="magnifying-glass" href="/vectoriadb/api-reference/interfaces/search">
    Search interfaces
  </Card>

  <Card title="add()" icon="plus" href="/vectoriadb/api-reference/vectoriadb/add">
    Adding documents
  </Card>
</CardGroup>
