Skip to content

Commit f96f0f0

Browse files
authored
Sentinel Documentation (#2)
1 parent ff8f41c commit f96f0f0

7 files changed

Lines changed: 13 additions & 110 deletions

File tree

.github/workflows/docs.yml

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -73,58 +73,3 @@ jobs:
7373
body: '⚠️ **Documentation is out of sync with the code!**\n\nPlease run `python docs/generate_docs.py` and commit the updated documentation files.'
7474
})
7575
76-
build:
77-
runs-on: ubuntu-latest
78-
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request'
79-
needs: [check-docs]
80-
# Make this job informational only for PRs - don't block PR
81-
continue-on-error: ${{ github.event_name == 'pull_request' }}
82-
steps:
83-
- name: Checkout repository
84-
uses: actions/checkout@v4
85-
86-
- name: Set up Python
87-
uses: actions/setup-python@v5
88-
with:
89-
python-version: '3.11'
90-
cache: 'pip'
91-
92-
- name: Install Poetry
93-
run: |
94-
curl -sSL https://install.python-poetry.org | python3 -
95-
echo "$HOME/.local/bin" >> $GITHUB_PATH
96-
97-
- name: Install dependencies
98-
run: |
99-
poetry install --with docs
100-
101-
- name: Generate RST files
102-
run: |
103-
cd ${{ github.workspace }}
104-
poetry run python docs/generate_docs.py
105-
106-
- name: Build documentation
107-
run: |
108-
cd ${{ github.workspace }}/docs
109-
poetry run sphinx-build -b html source build/html
110-
111-
- name: Setup Pages
112-
uses: actions/configure-pages@v4
113-
114-
- name: Upload artifact
115-
uses: actions/upload-pages-artifact@v3
116-
with:
117-
path: ${{ github.workspace }}/docs/build/html
118-
119-
deploy:
120-
# Only deploy on push to main or workflow_dispatch, skip on PRs
121-
if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
122-
needs: build
123-
environment:
124-
name: github-pages
125-
url: ${{ steps.deployment.outputs.page_url }}
126-
runs-on: ubuntu-latest
127-
steps:
128-
- name: Deploy to GitHub Pages
129-
id: deployment
130-
uses: actions/deploy-pages@v4

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ saved_config = index.save(
109109
aws_access_key_id="YOUR_ACCESS_KEY_ID", # Optional if using environment credentials
110110
aws_secret_access_key="YOUR_SECRET_ACCESS_KEY" # Optional if using environment credentials
111111
)
112-
113-
# If you need to extract the model name from an existing SentenceTransformer instance (best effort):
114-
from sentinel.embeddings.sbert import extract_model_name_from_sentence_transformer
115-
model_name = extract_model_name_from_sentence_transformer(model)
116-
# Returns the model name if it can be determined, or None otherwise
117112
```
118113

119114
## How It Works
@@ -186,6 +181,15 @@ poetry run sphinx-build -b html source build/html
186181

187182
Then open `docs/build/html/index.html` in your browser.
188183

184+
## Examples
185+
To run the notebook examples
186+
```bash
187+
# Install with examples dependencies
188+
poetry install --with examples
189+
poetry install --extras=sbert
190+
poetry run jupyter notebook
191+
```
192+
189193
## License
190194

191195
Apache License 2.0
File renamed without changes.
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ sentinel.score_types
2626
:undoc-members:
2727
:show-inheritance:
2828

29-
sentinel.sentinel
29+
sentinel.sentinel_local_index
3030
-----------------------------
3131

32-
.. automodule:: sentinel.sentinel
32+
.. automodule:: sentinel.sentinel_local_index
3333
:members:
3434
:undoc-members:
3535
:show-inheritance:

src/sentinel/embeddings/sbert.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,46 +46,6 @@ def get_sentence_transformer_and_scaling_fn(
4646

4747
return model, None
4848

49-
50-
def extract_model_name_from_sentence_transformer(
51-
model: SentenceTransformer,
52-
) -> Optional[str]:
53-
"""
54-
Attempt to extract the model name from a SentenceTransformer instance.
55-
56-
This is a best-effort function as SentenceTransformer doesn't directly store
57-
the original model name. It tries to infer it from the model's configuration.
58-
59-
Args:
60-
model: A SentenceTransformer model instance
61-
62-
Returns:
63-
A string representing the best guess at the model name, or
64-
None if it cannot be determined
65-
"""
66-
# Try to get the name from the model's modules
67-
if hasattr(model, "modules") and model.modules:
68-
# Most SentenceTransformer models use a Transformer as the first module
69-
if hasattr(model.modules[0], "auto_model") and hasattr(
70-
model.modules[0].auto_model, "config"
71-
):
72-
# Try to get the name from the config
73-
if hasattr(model.modules[0].auto_model.config, "name_or_path"):
74-
return model.modules[0].auto_model.config.name_or_path
75-
76-
# Try to get from the model's save directory name
77-
if hasattr(model, "get_sentence_embedding_dimension") and hasattr(
78-
model, "get_config_dict"
79-
):
80-
config = model.get_config_dict()
81-
if "__path__" in config and config["__path__"]:
82-
# Extract the final path component as the model name
83-
return os.path.basename(os.path.normpath(config["__path__"]))
84-
85-
# Return None if we can't determine the name
86-
return None
87-
88-
8949
def e5_scaling_function(score: float) -> float:
9050
"""
9151
Scale the similarity score for E5 embeddings.

src/sentinel/sentinel_local_index.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ def __init__(
9393
`model, scale_fn = get_sentence_transformer_and_scaling_fn(encoder_model_name_or_path)`
9494
9595
When saving the index, you must provide the exact encoder_model_name_or_path
96-
as SentenceTransformer doesn't store the original model name. If needed, you can use
97-
`sentinel.embeddings.sbert.extract_model_name_from_sentence_transformer(model)`
98-
to attempt extracting the model name, but this is a best-effort function that returns
99-
None if it cannot determine the model name.
96+
as SentenceTransformer doesn't store the original model name.
10097
10198
Use the class method `load` to load an index from S3 or local storage.
10299
"""
@@ -139,10 +136,7 @@ def save(
139136
path: Path to save the index to (local directory or S3 URI).
140137
encoder_model_name_or_path: Name or path of the sentence transformer encoder model used.
141138
This must be the exact name used to create the SentenceTransformer as it cannot be
142-
reliably extracted from the model instance. If you need to try extracting the model name
143-
from an existing instance, use
144-
`sentinel.embeddings.sbert.extract_model_name_from_sentence_transformer(model)`,
145-
which will return the model name if it can be determined or None otherwise.
139+
reliably extracted from the model instance.
146140
aws_access_key_id: Optional AWS access key ID for S3 access.
147141
aws_secret_access_key: Optional AWS secret access key for S3 access.
148142

0 commit comments

Comments
 (0)