{"id":37628041,"url":"https://github.com/rishiraj/spanking","last_synced_at":"2026-01-16T10:52:27.863Z","repository":{"id":233183799,"uuid":"786242307","full_name":"rishiraj/spanking","owner":"rishiraj","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-07T21:47:24.000Z","size":260,"stargazers_count":6,"open_issues_count":0,"forks_count":29,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-22T21:14:05.091Z","etag":null,"topics":["cosine-similarity","embeddings","genai","generative-ai","jax","llms","semantic-search","similarity-search","vector-database","vectors"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/spanking/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rishiraj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-13T21:09:12.000Z","updated_at":"2025-04-05T15:43:34.000Z","dependencies_parsed_at":"2024-04-14T12:02:54.021Z","dependency_job_id":"eb54bcf1-d78e-4790-b263-a5e34d396217","html_url":"https://github.com/rishiraj/spanking","commit_stats":null,"previous_names":["rishiraj/spanking"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rishiraj/spanking","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rishiraj%2Fspanking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rishiraj%2Fspanking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rishiraj%2Fspanking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rishiraj%2Fspanking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rishiraj","download_url":"https://codeload.github.com/rishiraj/spanking/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rishiraj%2Fspanking/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cosine-similarity","embeddings","genai","generative-ai","jax","llms","semantic-search","similarity-search","vector-database","vectors"],"created_at":"2026-01-16T10:52:27.744Z","updated_at":"2026-01-16T10:52:27.854Z","avatar_url":"https://github.com/rishiraj.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spanking 🍑👋\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ca href=\"http://127.0.0.1:5000\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/rishiraj/spanking/main/assets/home.png\"/\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003ca href=\"http://127.0.0.1:5000/search\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/rishiraj/spanking/main/assets/search.png\"/\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nTo use the 🍑👋 `VectorDB` class and access its functionality through a beautiful UI, follow these steps:\n\n## Cloning the Repository\n\nFirst, clone the repository to your local machine:\n\n```bash\ngit clone https://github.com/rishiraj/spanking.git\ncd spanking\n```\n\n## Running the UI\n\nTo manage your vector database through an intuitive web interface, you can run the provided `app.py` script:\n\n```bash\npython app.py\n```\n\nThis will start a local web server. You can then access the UI by navigating to `http://127.0.0.1:5000` in your web browser.\n\n### Features of the UI\n\n- **Add New Texts \u0026 Documents:** Easily add texts and documents to your vector database.\n- **View and Manage Entries:** See all stored texts and documents, update or delete them.\n- **Search Functionality:** Perform text or image-based searches and get structured JSON responses.\n- **Save and Load Database:** Save your database to a file or load it from a previously saved state.\n- **Metadata Handling:** Store and retrieve metadata associated with each text/document.\n\n## Using the 🍑👋 `VectorDB` Class Programmatically\n\nIf you prefer working with code, you can interact with the `VectorDB` class directly. Here’s how:\n\n### 1. **Create an Instance:**\n\n```python\nfrom spanking import VectorDB\nvector_db = VectorDB(model_name='BAAI/bge-base-en-v1.5')\n```\n\nYou can optionally specify a different pre-trained sentence transformer model by passing its name to the constructor.\n\n### 2. **Add Texts with Metadata:**\n\n```python\ntexts = [\"i eat pizza\", \"i play chess\", \"i drive bus\"]\nmetadatas = [{\"category\": \"food\"}, {\"category\": \"game\"}, {\"category\": \"transport\"}]\nvector_db.add_texts(texts, metadatas)\n```\n\nThis will encode the texts into embeddings, store them, and associate metadata with each entry.\n\n### 3. **Add Documents:**\n\n```python\nvector_db.add_doc([\"sample.pdf\"])\n```\n\nThis extracts text from the PDF and stores it along with page metadata.\n\n### 4. **Search for Similar Texts or Images (Returns JSON):**\n\n```python\nquery = \"we play football\"\ntext_results = vector_db.search(query, top_k=2, type='text')\nprint(text_results)  # JSON output\n```\n\nFor image-based search:\n\n```python\nimage_url = \"https://example.com/image.jpg\"\nimage_results = vector_db.search(image_url, top_k=2, type='image')\nprint(image_results)  # JSON output\n```\n\nThe `search` method now returns structured JSON with text, similarity score, and metadata.\n\n### 5. **Delete a Text:**\n\n```python\nindex = 1\nvector_db.delete_text(index)\n```\n\nRemoves the text and its corresponding metadata.\n\n### 6. **Update a Text with Metadata:**\n\n```python\nindex = 0\nnew_text = \"i enjoy eating pizza\"\nnew_metadata = {\"category\": \"food\", \"updated\": True}\nvector_db.update_text(index, new_text, new_metadata)\n```\n\nUpdates both text and metadata at the specified index.\n\n### 7. **Save the Database:**\n\n```python\nvector_db.save('vector_db.pkl')\n```\n\n### 8. **Load the Database:**\n\n```python\nvector_db = VectorDB.load('vector_db.pkl')\n```\n\n### 9. **Convert to DataFrame (Includes Metadata):**\n\n```python\ndf = vector_db.to_df()\nprint(df.head())\n```\n\n### 10. **Iterate Over Stored Texts \u0026 Metadata:**\n\n```python\nfor text, metadata in vector_db:\n    print(text, metadata)\n```\n\n### 11. **Access Individual Entries by Index:**\n\n```python\nindex = 2\ntext, metadata = vector_db[index]\nprint(text, metadata)\n```\n\n### 12. **Get the Number of Entries:**\n\n```python\nnum_entries = len(vector_db)\nprint(num_entries)\n```\n\n## Example Usage\n\nHere's an example demonstrating the updated 🍑👋 `VectorDB` class:\n\n```python\nfrom spanking import VectorDB\nvector_db = VectorDB()\n\n# Add texts with metadata\ntexts = [\"i eat pizza\", \"i play chess\", \"i drive bus\"]\nmetadatas = [{\"category\": \"food\"}, {\"category\": \"game\"}, {\"category\": \"transport\"}]\nvector_db.add_texts(texts, metadatas)\n\n# Search for similar texts\nquery = \"we play football\"\nresults = vector_db.search(query, top_k=2)\nprint(results)  # JSON output\n\n# Update a text with new metadata\nvector_db.update_text(1, \"i enjoy playing chess\", {\"category\": \"game\", \"updated\": True})\n\n# Delete a text\nvector_db.delete_text(2)\n\n# Save the database\nvector_db.save('vector_db.pkl')\n\n# Load the database\nloaded_vector_db = VectorDB.load('vector_db.pkl')\n\n# Iterate over stored texts and metadata\nfor text, metadata in loaded_vector_db:\n    print(text, metadata)\n\n# Convert to dataframe\ndf = loaded_vector_db.to_df()\nprint(df.head())\n```\n\nThis example demonstrates how to create a 🍑👋 `VectorDB` instance, add texts with metadata, search, update, delete, and work with the stored data in a structured format.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frishiraj%2Fspanking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frishiraj%2Fspanking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frishiraj%2Fspanking/lists"}