Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix embeddings database update lancedb #385

Merged
merged 4 commits into from
Nov 12, 2024
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
93 changes: 31 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twinny",
"displayName": "twinny - AI Code Completion and Chat",
"description": "Locally hosted AI code completion plugin for vscode",
"version": "3.18.12",
"version": "3.19.0",
"icon": "assets/icon.png",
"keywords": [
"code-inference",
Expand Down Expand Up @@ -464,7 +464,7 @@
"web-tree-sitter": "^0.22.1"
},
"dependencies": {
"@lancedb/lancedb": "^0.9.0",
"@lancedb/lancedb": "^0.12.0",
"@tiptap/extension-mention": "^2.5.9",
"@tiptap/extension-placeholder": "^2.5.9",
"@tiptap/pm": "^2.5.9",
Expand Down
4 changes: 0 additions & 4 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export const EXTENSION_CONTEXT_NAME = {
twinnyOverlapSize: "twinnyOverlapSize",
twinnyRelevantFilePaths: "twinnyRelevantFilePaths",
twinnyRelevantCodeSnippets: "twinnyRelevantCodeSnippets",
twinnyVectorSearchMetric: "twinnyVectorSearchMetric",
twinnySymmetryTab: "twinnySymmetryTab",
twinnyEnableRag: "twinnyEnableRag",
}
Expand Down Expand Up @@ -338,9 +337,6 @@ export const WASM_LANGUAGES: { [key: string]: string } = {

export const DEFAULT_RELEVANT_FILE_COUNT = 10
export const DEFAULT_RELEVANT_CODE_COUNT = 5
export const DEFAULT_VECTOR_SEARCH_METRIC = "l2"

export const EMBEDDING_METRICS = ["cosine", "l2", "dot"]

export const MULTILINE_OUTSIDE = [
"class_body",
Expand Down
2 changes: 1 addition & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export interface ChunkOptions {
}

export type Embedding = {
embeddings: number[]
embeddings: [number[]]
}

export type EmbeddedDocument = {
Expand Down
15 changes: 0 additions & 15 deletions src/extension/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
DEFAULT_RELEVANT_CODE_COUNT,
DEFAULT_RELEVANT_FILE_COUNT,
DEFAULT_RERANK_THRESHOLD,
DEFAULT_VECTOR_SEARCH_METRIC,
EVENT_NAME,
EXTENSION_CONTEXT_NAME,
EXTENSION_SESSION_NAME,
Expand Down Expand Up @@ -118,18 +117,11 @@ export class ChatService extends Base {
) as number
const relevantFileCount = Number(stored) || DEFAULT_RELEVANT_FILE_COUNT

const storedMetric = this._context?.globalState.get(
`${EVENT_NAME.twinnyGlobalContext}-${EXTENSION_CONTEXT_NAME.twinnyVectorSearchMetric}`
) as number

const metric = storedMetric || DEFAULT_VECTOR_SEARCH_METRIC

const filePaths =
(await this._db.getDocuments(
embedding,
relevantFileCount,
table,
metric as "cosine" | "l2" | "dot"
)) || []

if (!filePaths.length) return []
Expand Down Expand Up @@ -226,11 +218,6 @@ export class ChatService extends Base {

if (!embedding) return ""

const storedMetric = this._context?.globalState.get(
`${EVENT_NAME.twinnyGlobalContext}-${EXTENSION_CONTEXT_NAME.twinnyVectorSearchMetric}`
) as number
const metric = storedMetric || DEFAULT_VECTOR_SEARCH_METRIC

const query = relevantFiles?.length
? `file IN ("${relevantFiles.map((file) => file[0]).join("\",\"")}")`
: ""
Expand All @@ -240,7 +227,6 @@ export class ChatService extends Base {
embedding,
Math.round(relevantCodeCount / 2),
table,
metric as "cosine" | "l2" | "dot",
query
)) || []

Expand All @@ -249,7 +235,6 @@ export class ChatService extends Base {
embedding,
Math.round(relevantCodeCount / 2),
table,
metric as "cosine" | "l2" | "dot"
)) || []

const documents = [...embeddedDocuments, ...queryEmbeddedDocuments]
Expand Down
Loading