Skip to content

Commit 16c4e90

Browse files
Remove dead score function and fix linting issues
- Remove unused score function from main.py (dead code) - Fix flake8 line length issues in Python client - Fix markdownlint issues across all markdown files: - Break long lines to comply with 80-character limit - Add proper spacing around headings and lists - Fix code block spacing issues - All linting tools now pass without errors
1 parent 0f596ec commit 16c4e90

File tree

7 files changed

+147
-53
lines changed

7 files changed

+147
-53
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
ruff check src
2828
black --check src
2929
- name: Security audit
30+
id: security-audit
3031
continue-on-error: true
3132
run: |
3233
safety scan --json > safety-results.json
@@ -39,6 +40,24 @@ jobs:
3940
path: |
4041
safety-results.json
4142
audit-results.json
43+
- name: Security audit failure notification
44+
if: failure() && steps.security-audit.outcome == 'failure'
45+
run: |
46+
echo "::warning::Security audit failed! Check the security-audit-results artifact for details."
47+
echo "::group::Safety scan results"
48+
if [ -f safety-results.json ]; then
49+
cat safety-results.json
50+
else
51+
echo "safety-results.json not found"
52+
fi
53+
echo "::endgroup::"
54+
echo "::group::Pip audit results"
55+
if [ -f audit-results.json ]; then
56+
cat audit-results.json
57+
else
58+
echo "audit-results.json not found"
59+
fi
60+
echo "::endgroup::"
4261
- name: Import smoke test
4362
run: |
4463
python - << 'PY'

CODE_OF_CONDUCT.md

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
## Our Pledge
44

5-
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, caste, color, religion, or sexual
10+
identity and orientation.
611

7-
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
814

915
## Our Standards
1016

11-
Examples of behavior that contributes to a positive environment for our community include:
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
1219

1320
* Using welcoming and inclusive language
1421
* Being respectful of differing viewpoints and experiences
@@ -18,59 +25,102 @@ Examples of behavior that contributes to a positive environment for our communit
1825

1926
Examples of unacceptable behavior include:
2027

21-
* The use of sexualized language or imagery, and sexual attention or advances of any kind
28+
* The use of sexualized language or imagery, and sexual attention or advances
29+
of any kind
2230
* Trolling, insulting or derogatory comments, and personal or political attacks
2331
* Public or private harassment
24-
* Publishing others' private information, such as a physical or email address, without their explicit permission
25-
* Other conduct which could reasonably be considered inappropriate in a professional setting
32+
* Publishing others' private information, such as a physical or email address,
33+
without their explicit permission
34+
* Other conduct which could reasonably be considered inappropriate in a
35+
professional setting
2636

2737
## Enforcement Responsibilities
2838

29-
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
39+
Community leaders are responsible for clarifying and enforcing our standards of
40+
acceptable behavior and will take appropriate and fair corrective action in
41+
response to any behavior that they deem inappropriate, threatening, offensive,
42+
or harmful.
3043

31-
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
44+
Community leaders have the right and responsibility to remove, edit, or reject
45+
comments, commits, code, wiki edits, issues, and other contributions that are
46+
not aligned to this Code of Conduct, and will communicate reasons for
47+
moderation decisions when appropriate.
3248

3349
## Scope
3450

35-
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
51+
This Code of Conduct applies within all community spaces, and also applies when
52+
an individual is officially representing the community in public spaces.
53+
Examples of representing our community include using an official project e-mail
54+
address, posting via an official social media account, or acting as an appointed
55+
representative at an online or offline event.
3656

3757
## Enforcement
3858

39-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [[email protected]](mailto:[email protected]). All complaints will be reviewed and investigated promptly and fairly.
59+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
60+
reported to the community leaders responsible for enforcement at
61+
62+
complaints will be reviewed and investigated promptly and fairly.
4063

41-
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
64+
All community leaders are obligated to respect the privacy and security of the
65+
reporter of any incident.
4266

4367
## Enforcement Guidelines
4468

45-
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
69+
Community leaders will follow these Community Impact Guidelines in determining
70+
the consequences for any action they deem in violation of this Code of Conduct:
4671

4772
### 1. Correction
48-
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
4973

50-
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
74+
**Community Impact**: Use of inappropriate language or other behavior deemed
75+
unprofessional or unwelcome in the community.
76+
77+
**Consequence**: A private, written warning from community leaders, providing
78+
clarity around the nature of the violation and an explanation of why the
79+
behavior was inappropriate. A public apology may be requested.
5180

5281
### 2. Warning
82+
5383
**Community Impact**: A violation through a single incident or series of actions.
5484

55-
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
85+
**Consequence**: A warning with consequences for continued behavior. No
86+
interaction with the people involved, including unsolicited interaction with
87+
those enforcing the Code of Conduct, for a specified period of time. This
88+
includes avoiding interactions in community spaces as well as external channels
89+
like social media. Violating these terms may lead to a temporary or permanent
90+
ban.
5691

5792
### 3. Temporary Ban
58-
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
5993

60-
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
94+
**Community Impact**: A serious violation of community standards, including
95+
sustained inappropriate behavior.
96+
97+
**Consequence**: A temporary ban from any sort of interaction or public
98+
communication with the community for a specified period of time. No public or
99+
private interaction with the people involved, including unsolicited interaction
100+
with those enforcing the Code of Conduct, is allowed during this period.
101+
Violating these terms may lead to a permanent ban.
61102

62103
### 4. Permanent Ban
63-
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
64104

65-
**Consequence**: A permanent ban from any sort of public interaction within the community.
105+
**Community Impact**: Demonstrating a pattern of violation of community
106+
standards, including sustained inappropriate behavior, harassment of an
107+
individual, or aggression toward or disparagement of classes of individuals.
108+
109+
**Consequence**: A permanent ban from any sort of public interaction within the
110+
community.
66111

67112
## Attribution
68113

69-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
114+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
115+
version 2.1, available at
116+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
70117

71-
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
118+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
119+
enforcement ladder][Mozilla CoC].
72120

73-
For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].
121+
For answers to common questions about this code of conduct, see the FAQ at
122+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
123+
[https://www.contributor-covenant.org/translations][translations].
74124

75125
[homepage]: https://www.contributor-covenant.org
76126
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html

CONTRIBUTING.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Contributing to ContextForge Memory
22

3-
Thank you for your interest in contributing to ContextForge Memory! This document provides guidelines for contributing to the project.
3+
Thank you for your interest in contributing to ContextForge Memory! This
4+
document provides guidelines for contributing to the project.
45

56
## Code of Conduct
67

7-
This project adheres to our [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
8+
This project adheres to our [Code of Conduct](CODE_OF_CONDUCT.md). By
9+
participating, you are expected to uphold this code.
810

911
## Getting Started
1012

@@ -36,19 +38,22 @@ python -m pytest
3638
### Branch Naming
3739

3840
Use descriptive branch names:
41+
3942
- `feature/add-new-endpoint`
4043
- `bugfix/fix-search-filtering`
4144
- `docs/update-readme`
4245

4346
### Commit Messages
4447

4548
Write clear, descriptive commit messages:
49+
4650
- Use present tense ("Add feature" not "Added feature")
4751
- Capitalize the first letter
4852
- No period at the end
4953
- Reference issues when applicable
5054

5155
Examples:
56+
5257
- `Add support for custom metadata validation`
5358
- `Fix search results ordering bug (#123)`
5459
- `Update API documentation`
@@ -58,11 +63,13 @@ Examples:
5863
### Before Submitting
5964

6065
1. **Run Tests**: Ensure all tests pass
66+
6167
```bash
6268
python -m pytest
6369
```
6470

6571
2. **Run Linting**: Fix any linting issues
72+
6673
```bash
6774
ruff check src
6875
black src
@@ -177,4 +184,5 @@ If you have questions about contributing, please:
177184

178185
## Thank You
179186

180-
Thank you for contributing to ContextForge Memory! Your contributions help make this project better for everyone.
187+
Thank you for contributing to ContextForge Memory! Your contributions help make
188+
this project better for everyone.

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
## ContextForge Memory (v0)
1+
# ContextForge Memory (v0)
22

3-
Lightweight external memory layer providing store, search, and embed APIs for multi-repo reuse (Brainstorm, Cursor, and others).
3+
Lightweight external memory layer providing store, search, and embed APIs for
4+
multi-repo reuse (Brainstorm, Cursor, and others).
5+
6+
## Features
47

5-
### Features
68
- Versioned API: `/v0/` with `store`, `search`, `embed`.
79
- Deterministic, minimal embedding (hash-based) for baseline functionality.
810
- Pluggable storage (default: JSONL on disk).
911

10-
### Quickstart
12+
## Quickstart
13+
1114
```bash
1215
python -m venv .venv && source .venv/bin/activate
1316
pip install -r requirements.txt
1417
uvicorn src.contextforge_memory.main:app --host 0.0.0.0 --port 8085
1518
```
1619

17-
### API Endpoints
20+
## API Endpoints
21+
1822
- `GET /v0/health`
1923
- `POST /v0/store`
2024
- `POST /v0/search`
2125
- `POST /v0/embed`
2226

2327
See `openapi/openapi-v0.yaml` for schemas.
2428

25-
### Clients
29+
## Clients
30+
2631
- Python: `clients/python/contextforge_client.py`
2732
- TypeScript: `clients/typescript/contextforgeClient.ts`
2833

29-
### CI
30-
Basic import smoke in GitHub Actions (see `.github/workflows/ci.yml`).
31-
34+
## CI
3235

36+
Basic import smoke in GitHub Actions (see `.github/workflows/ci.yml`).

SECURITY.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ We currently support the following versions of ContextForge Memory:
1010

1111
## Reporting a Vulnerability
1212

13-
We take security vulnerabilities seriously. If you discover a security vulnerability in ContextForge Memory, please report it to us as described below.
13+
We take security vulnerabilities seriously. If you discover a security
14+
vulnerability in ContextForge Memory, please report it to us as described
15+
below.
1416

1517
### How to Report
1618

@@ -35,7 +37,8 @@ When reporting a vulnerability, please include:
3537

3638
### Security Updates
3739

38-
Security updates will be released as patch versions (e.g., 0.1.1) and will be announced in the project's release notes.
40+
Security updates will be released as patch versions (e.g., 0.1.1) and will be
41+
announced in the project's release notes.
3942

4043
## Security Best Practices
4144

@@ -49,4 +52,6 @@ When using ContextForge Memory:
4952

5053
## Acknowledgments
5154

52-
We appreciate the security research community's efforts to help keep our software secure. We will acknowledge security researchers who responsibly disclose vulnerabilities to us.
55+
We appreciate the security research community's efforts to help keep our
56+
software secure. We will acknowledge security researchers who responsibly
57+
disclose vulnerabilities to us.

clients/python/contextforge_client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ def health(self) -> Dict[str, Any]:
1515
return r.json()
1616

1717
def store(self, items: List[Dict[str, Any]]) -> Dict[str, Any]:
18-
r = self._client.post(f"{self.base_url}/v0/store", json={"items": items})
18+
r = self._client.post(
19+
f"{self.base_url}/v0/store", json={"items": items}
20+
)
1921
r.raise_for_status()
2022
return r.json()
2123

22-
def search(self, namespace: str, project_id: str, query: str, top_k: int = 5) -> Dict[str, Any]:
24+
def search(
25+
self, namespace: str, project_id: str, query: str, top_k: int = 5
26+
) -> Dict[str, Any]:
2327
payload = {
2428
"namespace": namespace,
2529
"project_id": project_id,
@@ -31,8 +35,8 @@ def search(self, namespace: str, project_id: str, query: str, top_k: int = 5) ->
3135
return r.json()
3236

3337
def embed(self, texts: List[str]) -> Dict[str, Any]:
34-
r = self._client.post(f"{self.base_url}/v0/embed", json={"texts": texts})
38+
r = self._client.post(
39+
f"{self.base_url}/v0/embed", json={"texts": texts}
40+
)
3541
r.raise_for_status()
3642
return r.json()
37-
38-

src/contextforge_memory/main.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ def search(req: SearchRequest) -> SearchResponse:
8787
return SearchResponse(results=results)
8888
query_vec = _embed_text(req.query)
8989

90-
def score(a: List[float], b: List[float]) -> float:
91-
# Simple L2 distance inverted
92-
return -sum((x - y) ** 2 for x, y in zip(a, b))
93-
90+
# Store items with their precomputed embeddings
91+
items_with_embeddings: List[tuple[MemoryItem, List[float]]] = []
9492
with bucket.open("r", encoding="utf-8") as f:
9593
for line in f:
9694
data = orjson.loads(line)
@@ -99,12 +97,18 @@ def score(a: List[float], b: List[float]) -> float:
9997
or data.get("project_id") != req.project_id
10098
):
10199
continue
102-
results.append(MemoryItem(**data))
103-
104-
# Sort by score descending using precomputed query_vec
105-
results.sort(
106-
key=lambda it: -sum(
107-
(x - y) ** 2 for x, y in zip(query_vec, _embed_text(it.text))
100+
item = MemoryItem(**data)
101+
# Compute embedding once during the initial loop
102+
embedding = _embed_text(item.text)
103+
items_with_embeddings.append((item, embedding))
104+
105+
# Sort by score descending using precomputed embeddings
106+
items_with_embeddings.sort(
107+
key=lambda item_embed: -sum(
108+
(x - y) ** 2 for x, y in zip(query_vec, item_embed[1])
108109
)
109110
)
110-
return SearchResponse(results=results[: max(1, req.top_k)])
111+
112+
# Extract just the MemoryItem objects for the response
113+
results = [item for item, _ in items_with_embeddings[: max(1, req.top_k)]]
114+
return SearchResponse(results=results)

0 commit comments

Comments
 (0)