Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Index
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Llama Index
Commits
1f943903
Unverified
Commit
1f943903
authored
1 year ago
by
Pavan Ramkumar
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
LanceDBVectorStore bug fixes (#10404)
parent
ecec138c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llama_index/vector_stores/lancedb.py
+25
-9
25 additions, 9 deletions
llama_index/vector_stores/lancedb.py
with
25 additions
and
9 deletions
llama_index/vector_stores/lancedb.py
+
25
−
9
View file @
1f943903
...
...
@@ -19,6 +19,7 @@ from llama_index.vector_stores.types import (
VectorStoreQueryResult
,
)
from
llama_index.vector_stores.utils
import
(
DEFAULT_DOC_ID_KEY
,
DEFAULT_TEXT_KEY
,
legacy_metadata_dict_to_node
,
metadata_dict_to_node
,
...
...
@@ -52,7 +53,8 @@ def _to_llama_similarities(results: DataFrame) -> List[float]:
class
LanceDBVectorStore
(
VectorStore
):
"""
The LanceDB Vector Store.
"""
The LanceDB Vector Store.
Stores text and embeddings in LanceDB. The vector store will open an existing
LanceDB dataset or create the dataset if it does not exist.
...
...
@@ -61,6 +63,8 @@ class LanceDBVectorStore(VectorStore):
uri (str, required): Location where LanceDB will store its files.
table_name (str, optional): The table name where the embeddings will be stored.
Defaults to
"
vectors
"
.
vector_column_name (str, optional): The vector column name in the table if different from default.
Defaults to
"
vector
"
, in keeping with lancedb convention.
nprobes (int, optional): The number of probes used.
A higher number makes search more accurate but also slower.
Defaults to 20.
...
...
@@ -83,9 +87,11 @@ class LanceDBVectorStore(VectorStore):
self
,
uri
:
str
,
table_name
:
str
=
"
vectors
"
,
vector_column_name
:
str
=
"
vector
"
,
nprobes
:
int
=
20
,
refine_factor
:
Optional
[
int
]
=
None
,
text_key
:
str
=
DEFAULT_TEXT_KEY
,
doc_id_key
:
str
=
DEFAULT_DOC_ID_KEY
,
**
kwargs
:
Any
,
)
->
None
:
"""
Init params.
"""
...
...
@@ -98,8 +104,10 @@ class LanceDBVectorStore(VectorStore):
self
.
connection
=
lancedb
.
connect
(
uri
)
self
.
uri
=
uri
self
.
table_name
=
table_name
self
.
vector_column_name
=
vector_column_name
self
.
nprobes
=
nprobes
self
.
text_key
=
text_key
self
.
doc_id_key
=
doc_id_key
self
.
refine_factor
=
refine_factor
@property
...
...
@@ -165,7 +173,10 @@ class LanceDBVectorStore(VectorStore):
table
=
self
.
connection
.
open_table
(
self
.
table_name
)
lance_query
=
(
table
.
search
(
query
.
query_embedding
)
table
.
search
(
query
=
query
.
query_embedding
,
vector_column_name
=
self
.
vector_column_name
,
)
.
limit
(
query
.
similarity_top_k
)
.
where
(
where
)
.
nprobes
(
self
.
nprobes
)
...
...
@@ -174,28 +185,33 @@ class LanceDBVectorStore(VectorStore):
if
self
.
refine_factor
is
not
None
:
lance_query
.
refine_factor
(
self
.
refine_factor
)
results
=
lance_query
.
to_
df
()
results
=
lance_query
.
to_
pandas
()
nodes
=
[]
for
_
,
item
in
results
.
iterrows
():
try
:
node
=
metadata_dict_to_node
(
item
.
metadata
)
node
.
embedding
=
list
(
item
.
vector
)
node
.
embedding
=
list
(
item
[
self
.
vector
_column_name
]
)
except
Exception
:
# deprecated legacy logic for backward compatibility
_logger
.
debug
(
"
Failed to parse Node metadata, fallback to legacy logic.
"
)
metadata
,
node_info
,
_relation
=
legacy_metadata_dict_to_node
(
item
.
metadata
,
text_key
=
self
.
text_key
)
if
"
metadata
"
in
item
:
metadata
,
node_info
,
_relation
=
legacy_metadata_dict_to_node
(
item
.
metadata
,
text_key
=
self
.
text_key
)
else
:
metadata
,
node_info
=
{},
{}
node
=
TextNode
(
text
=
item
.
text
or
""
,
text
=
item
[
self
.
text_key
]
or
""
,
id_
=
item
.
id
,
metadata
=
metadata
,
start_char_idx
=
node_info
.
get
(
"
start
"
,
None
),
end_char_idx
=
node_info
.
get
(
"
end
"
,
None
),
relationships
=
{
NodeRelationship
.
SOURCE
:
RelatedNodeInfo
(
node_id
=
item
.
doc_id
),
NodeRelationship
.
SOURCE
:
RelatedNodeInfo
(
node_id
=
item
[
self
.
doc_id_key
]
),
},
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment