Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .claude/commands/context-compact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Prepare context for compaction: $ARGUMENTS

<ultrathink>
Context window approaching limit. Need to preserve essential information for task continuation.
</ultrathink>

<megaexpertise type="context-preservation-specialist">
Distill current work state to essential elements. Capture critical context for seamless continuation after compaction.
</megaexpertise>

<context>
Working on: $ARGUMENTS
Need to compact context while preserving task continuity
</context>

<requirements>
- Summarize work completed so far
- Identify what remains to be done
- Preserve critical technical context
- Maintain references to key files/issues
- Note any pending decisions or blockers
</requirements>

<actions>
1. Current Task State:
- Summarize the main objective in 1-2 sentences
- List completed subtasks (brief bullet points)
- Identify current working file/component

2. Technical Context:
- Key files modified: paths and purpose
- Important code patterns or decisions made
- Dependencies or integrations involved
- Any gotchas or edge cases discovered

3. Next Steps:
- Immediate next action (specific and actionable)
- Remaining subtasks in priority order
- Any blockers or dependencies

4. References:
- Linear issue ID (if applicable)
- Git branch name
- Key documentation or examples used
- Important test files or commands

5. Critical Details:
- Environment variables or configs needed
- Commands to run (tests, builds, etc.)
- Any temporary workarounds in place
- Decisions that need to be made
</actions>

Format output as:
```
## Task: [Brief description]

### Completed:
- [Item 1]
- [Item 2]

### Next Action:
[Specific next step with file path if applicable]

### Remaining Work:
1. [Task 1]
2. [Task 2]

### Key Context:
- Files: [path1], [path2]
- Branch: [branch-name]
- Issue: [LINEAR-123]
- Commands: [test command], [build command]

### Notes:
[Any critical information for continuation]
```

This ensures smooth continuation after context reset. Focus on what's essential for picking up exactly where we left off.

Take a deep breath in, count 1... 2... 3... and breathe out. You are now centered. Don't hold back. Give it your all.
3 changes: 1 addition & 2 deletions contextframe/builders/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
embedding models and services.
"""

import numpy as np
import os
from typing import List, Optional, Union

import numpy as np


def generate_sentence_transformer_embeddings(
text: str, model: str = "sentence-transformers/all-MiniLM-L6-v2"
Expand Down
2 changes: 1 addition & 1 deletion contextframe/embed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"create_embedder",
"embed_extraction_results",
"create_frame_records_with_embeddings",
]
]
63 changes: 30 additions & 33 deletions contextframe/embed/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@
@dataclass
class EmbeddingResult:
"""Result of an embedding operation from an encoding model.

Attributes:
embeddings: The generated embeddings as a list of float lists
model: The encoding model used (e.g., "text-embedding-ada-002")
dimension: The dimension of the embeddings
usage: Token usage information (if available)
metadata: Additional metadata from the encoding model
"""
embeddings: List[List[float]]

embeddings: list[list[float]]
model: str
dimension: int
usage: Optional[dict[str, int]] = None
usage: dict[str, int] | None = None
metadata: dict[str, Any] = None

def __post_init__(self):
"""Validate embeddings and set dimension."""
if self.metadata is None:
self.metadata = {}

# Validate all embeddings have same dimension
if self.embeddings:
first_dim = len(self.embeddings[0])
if not all(len(emb) == first_dim for emb in self.embeddings):
raise ValueError("All embeddings must have the same dimension")

# Set dimension from embeddings if not provided
if self.dimension is None:
self.dimension = first_dim
Expand All @@ -45,43 +46,39 @@ def __post_init__(self):

class EmbeddingProvider(ABC):
"""Abstract base class for encoding model providers.

This class defines the interface for different embedding providers
(OpenAI, Cohere, HuggingFace, etc.) that use encoding models to
transform text into vector representations.
"""
def __init__(self, model: str, api_key: Optional[str] = None):

def __init__(self, model: str, api_key: str | None = None):
"""Initialize the embedding provider.

Args:
model: The encoding model identifier (e.g., "text-embedding-ada-002")
api_key: Optional API key (uses environment variable if not provided)
"""
self.model = model
self.api_key = api_key

@abstractmethod
def embed(
self,
texts: Union[str, List[str]],
**kwargs
) -> EmbeddingResult:
def embed(self, texts: str | list[str], **kwargs) -> EmbeddingResult:
"""Generate embeddings using the encoding model.

Args:
texts: Single text or list of texts to encode
**kwargs: Additional provider-specific arguments

Returns:
EmbeddingResult containing the embeddings from the encoding model
"""
pass

@abstractmethod
def get_model_info(self) -> dict[str, Any]:
"""Get information about the encoding model.

Returns:
Dictionary with model information including:
- dimension: The embedding dimension
Expand All @@ -90,40 +87,40 @@ def get_model_info(self) -> dict[str, Any]:
- capabilities: List of capabilities
"""
pass

@property
@abstractmethod
def supports_batch(self) -> bool:
"""Whether this encoding model supports batch processing."""
pass

@property
def max_batch_size(self) -> Optional[int]:
def max_batch_size(self) -> int | None:
"""Maximum batch size supported by the encoding model."""
return None
def validate_texts(self, texts: Union[str, List[str]]) -> List[str]:

def validate_texts(self, texts: str | list[str]) -> list[str]:
"""Validate and normalize input texts for the encoding model.

Args:
texts: Single text or list of texts

Returns:
List of validated texts

Raises:
ValueError: If texts are invalid for the encoding model
"""
if isinstance(texts, str):
texts = [texts]

if not texts:
raise ValueError("No texts provided for embedding")

if not all(isinstance(t, str) for t in texts):
raise ValueError("All texts must be strings")

if not all(t.strip() for t in texts):
raise ValueError("Empty texts cannot be embedded")
return texts

return texts
Loading